ios - 如何使 UITextField 文本输入在 5-6 个空格字符后开始

标签 ios objective-c uitextfield text-alignment

<分区>

在后台使用两个 TextField 或使用标签/ View 。将 TextFields 放置在某些 View /标签/TextFields 上不是正确的开发。将标签或 View 放在左侧也不是正确的方法

enter image description here

我不认为下面的方法是正确的方法。所以我想要一个更好的解决方案

UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)];
leftView.backgroundColor = [UIColor clearColor];

textField.leftView = leftView;

textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

我们如何使用下面的方法来实现它

// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
     return CGRectInset( bounds , 10 , 10 );
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset( bounds , 10 , 10 );
}

我能够使用 .但是有没有更好的方法呢

Txt_SecurityAns.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
Txt_Email.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);

最佳答案

在 UITextField 中设置 paddingView...

UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,7,26)];
textField.leftView = leftView;
textField.leftViewMode = UITextFieldViewModeAlways;

关于ios - 如何使 UITextField 文本输入在 5-6 个空格字符后开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29818518/

上一篇:ios - objective-C++ 中的 UIGestureRecognizer

下一篇:ios - 忽略 #pragma 发出的警告

相关文章:

IOS:如果 UITextField 为空,如何让占位符文本返回?

uitextfield - SwiftUI 将图像添加到文本字段的左侧

iphone - UIRefreshControl在iOS6中使用,但在iOS5中不使用

objective-c - 我可以使用协议(protocol)对象作为 NSDictionary 中的键吗?

ios - 如何从 UITextField 中获取非英文字符并将其视为普通字符

iphone - 核心图 : Allow horizontal scrolling in positive quadrant only

iphone - Game Center 不在排行榜 iPhone 中显示分数

ios - SpriteKit 中的动画路径绘制

ios - Mutablearray 中的 UIImage 未显示

ios - 使用 UIFont 时处理点或像素