我想更具体地将文本定位在文本字段中。
我当前的代码:
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/