这是我的问题:
查看第一个字符, k 的左下角未显示。
我试过了:
- (CGRect)textRectForBounds:(CGRect)bounds{
return CGRectInset( bounds , 20 , 20 );
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return CGRectInset( bounds , 20 , 20 );
}
还有这个:
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 20)] ;
myText.leftView = paddingView;
myText.leftViewMode = UITextFieldViewModeAlways;
但没有机会!
答案 0 :(得分:1)
不确定这是否是一个很好的解决方案,但是一旦我面对这样的事情,我所做的就是在字符串的开头添加一个空格,修复了问题,稍微启动了一下缩进stringByAppendingString
。
答案 1 :(得分:1)
很抱歉回答这么晚,但可能是我的回答可以帮助那些寻找类似解决方案的人
这是我为填充做的。 在.m文件的顶部添加以下代码,您需要使用paading
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
@implementation UITextField (custom)
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.origin.x + 10, bounds.origin.y + 8,
bounds.size.width - 20, bounds.size.height - 16);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
@end
#pragma clang diagnostic pop
<强> P.S。这些指令用于防止对类别重写方法发出警告。