ios - 在文本字段中定位文本

标签 ios objective-c uitextfield

我想更具体地将文本定位在文本字段中。

我当前的代码:

UITextField * textFieldIndustry = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 465, 68)];
textFieldIndustry.font = [UIFont systemFontOfSize:17.0];  
textFieldIndustry.placeholder = @"Tap to..";  
textFieldIndustry.textAlignment = NSTextAlignmentCenter;

这段代码:

textFieldIndustry.textAlignment = NSTextAlignmentCenter; 

将文本居中但不是我想要的位置。我如何使用例如 X 和 Y 定位?

最佳答案

您不能在 UITextField 不子类化的情况下隐式设置文本的位置。

您可以改用 UITextView,并且应该使用相同的方法:

UITextView *textView;
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
[textView setContentInset:insets];

您可以使用 this approach还可以对 UITextField 进行子类化。

关于ios - 在文本字段中定位文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16443003/

相关文章:

iphone - 当文本字段有输入时启用 UIBarButtonItem

ios - 是否可以在 IOS 模拟器中使用 Google Analytics 跟踪应用程序?

ios - 在 iOS 应用程序中上传视频的最佳做法

iphone - iOS中将键值对添加到plist文件时出现问题

ios - 转到不同 UITableViewCell 中的下一个 UITextField

ios - - (CGRect) textRectForBounds :(CGRect)bounds not being called

ios - Segues 与 UIViewControllerAnimatedTransitioning

ios - 编译到模拟器时如何在 Xcode 中排除框架

ios - 如果用户以编程方式点击 UITextfield,如何显示 UIDatePicker

ios - Objective-C 访问 Plist 中的特定项目