ios - 在图像后的 UITextField 中添加空间

标签 ios objective-c uitextfield

enter image description here

我的问题是,我创建了一个文本字段,它以 leftviewmode 作为图像,占位符位于文本字段中间的某个位置,当用户开始输入时,文本编辑应该开始。那么如何让我的文本从占位符所在的文本字段中间开始。我无法在 imageview 中设置 leftviewmode,因为我已经在其中添加了图像。我该怎么办?

UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"a_point30"]];
image.frame = CGRectMake(0, 0, image.image.size.width, image.image.size.height-10);
self.enterSource.leftViewMode = UITextFieldViewModeAlways; self.enterSource.leftView = image;

例如文本编辑应该从 hello world 占位符开始。

最佳答案

你可以做这样的事情

 UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]];
imgView.frame = CGRectMake(0.0, 0.0, dropDown.image.size.width+10.0, dropDown.image.size.height);
imgView.contentMode = UIViewContentModeLeft;
textField.leftView = imgView;
textField.leftViewMode = UITextFieldViewModeAlways;

关于ios - 在图像后的 UITextField 中添加空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36403350/

相关文章:

ios - 如何在运行时调整 XIB/NIB 内 subview 的大小

ios - 为什么 UIWindow backgroundColor 通常为黑色,而默认值为 nil 表示清晰的颜色

iphone - 检查单词在数组中是否有效

swift - 使用图层的 .roundedRect 与 cornerRadius 来制作圆角

ios - UITextField 货币格式从左到右

ios - 在 SpriteKit 中使用 Swift 截取和共享屏幕截图

ios - 无法检索 Shoutcast .pls 流

ios - Xcrun 没有嵌入传递的配置文件

ios - 如何以编程方式检查字符串的日期格式是否正确

ios - 如何在警报 View 中创建两个文本字段,IOS