iphone - UITextView 背景图像不适合 UITextView 框架的框架大小

标签 iphone ios uiimageview uiimage uitextview

我正在开发一个应用程序,我需要为大文本放置一个 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];

image of textbox which I am using for background Screen shots showing cursor on left corner outside the background image

最佳答案

试试这个:

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];

或者类似的东西。

关于iphone - UITextView 背景图像不适合 UITextView 框架的框架大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640385/

相关文章:

ios - 加载/下载带有空格后跟数字的 URL

iphone - 如何从地址簿 ios 以编程方式编辑电话号码值

Objective-C 核心动画或 OpenGL 以角度绘制阴影

ios - 恢复 UIVIew 动画时出现问题 : ios7?

iphone - 在iPhone上绘制自定义图形: CALayer vs. CGContext

iphone:如何在 webView 中放置主页按钮

objective-c - 在 iPad 中解析 XML 文件时如何处理 CDATA 标签

android - 我应该如何为混合移动应用程序进行平台特定代码管理(SVN)?

ios - Storyboard设计 iOS 所需的分辨率图形

iphone - 在 iOS 中对图层应用蒙版后如何捕获屏幕?