我是Objective c中的新手,我遇到了在寄存器表单的多个文本字段中填充的问题。 我有4个文本字段,这是我的代码,并尝试设置左边距:
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
paddingView.backgroundColor = [UIColor clearColor];
self.textField1.leftView = paddingView;
self.textField1.leftViewMode = UITextFieldViewModeAlways;
self.textField2.leftView = paddingView;
self.textField2.leftViewMode = UITextFieldViewModeAlways;
self.textField3.leftView = paddingView;
self.textField3.leftViewMode = UITextFieldViewModeAlways;
self.textField4.leftView = paddingView;
self.textField4.leftViewMode = UITextFieldViewModeAlways;
问题是它崩溃了,我找不到原因。有什么帮助吗?
答案 0 :(得分:1)
要在字段中重新定位文本,请将文本字段子类化为类似的内容(我实际上并未运行此代码,因此您可能需要对其进行调整):
@interface MyPaddedTextField : UITextField
- (CGRect)textRectForBounds:(CGRect)bounds {
CGRect r = [super textRectForBounds:bounds];
r.origin.x += 5;
r.size.width -= 5;
return r;
}
@end