【问题标题】:UITextView background image does not fit in frame size of UITextView frameUITextView 背景图像不适合 UITextView 框架的框架大小
【发布时间】:2013-02-01 05:35:07
【问题描述】:

我正在开发一个需要为大文本放置 UITextView 的应用程序。我有一个大小为 180X89 的背景图像(与 UITextView 帧大小相同)。将图像放在 UITextView 后面时,一切看起来都很好,但是当用户点击文本区域并出现键盘时,光标出现在图像边缘之外。

我希望光标出现在文本框中。

获取 UITextview 的代码

CGRect textViewFrame = CGRectMake(125.0f, 155.0f, 180.0f, 90.0f);
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.returnKeyType = UIReturnKeyDone;
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:  @"textbox.png"]];
textView.delegate = self;
[self.view addSubview:textView];

【问题讨论】:

  • 如果将其设置为背景图像,请尝试将 textView 放在 iamgeView.image = backgroundImage 的图像视图上

标签: iphone ios uiimageview uiimage uitextview


【解决方案1】:

试试这个:

UIImage     *bgImage     = [UIImage imageNamed:@"textbox.png"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];

CGRect textViewFrame = CGRectMake(125.0f, 155.0f, 180.0f, 90.0f);
bgImageView.frame    = textViewFrame;

UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];

textView.returnKeyType = UIReturnKeyDone;
textView.delegate      = self;

[self.view addSubview:bgImageView];
[self.view addSubview:textView];

或者类似的东西。

【讨论】:

    【解决方案2】:

    有非常简单的方法。只需在 TextView 后面使用 UIImageView 并将 UITextView 背景颜色设置为清晰颜色。

    【讨论】:

      【解决方案3】:

      在这种情况下,您可以做的是使UITextView 的大小更小,以便它恰好出现在您的背景图像中,并使用框架<QuartzCore>UITextView 提供角半径,例如@ 987654324@(导入框架的标头)。这种方法还会使UITextView 边缘有点圆度,使其看起来像你上面提供的图像。

      所以,简而言之,添加 UIImageView 然后在其上方添加 UITextView 并将 textview 的背景设置为 clearcolor 。希望这可以帮助 !!! :)

      【讨论】:

        【解决方案4】:

        在你的视图上添加 UIImageView,然后在 UIImageView 上添加 UITextView,内框为

        CGPointMake(10,10) as Origin
        

        CGSizeMake(imageView.frame.size.width - 20.0, imageView.frame.size.hieght - 20.0) as Size 的 textView。

        【讨论】:

        • 我该怎么做?你能否让我知道这样做的代码。现在我可以将光标放在文本框中,但是字母仍然被剪掉。我放置了 UIImageView 并在其上放置了 UiTextView 并使 textView.layer.cornerradious = 50;
        • 编辑了@glyytchy 答案。检查一下。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-05
        • 1970-01-01
        • 2013-09-22
        • 1970-01-01
        • 2011-05-03
        • 2012-09-08
        • 1970-01-01
        相关资源
        最近更新 更多