我已经有了为我的所有文本字段创建填充的解决方案,但我认为我需要简化它,因为我认为这太简单了:
// Padding Left and Right for textfield
UIView *fieldEmail = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_fieldEmail.leftViewMode = UITextFieldViewModeAlways;
_fieldEmail.leftView = fieldEmail;
UIView *fieldPassword = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_fieldPassword.leftViewMode = UITextFieldViewModeAlways;
_fieldPassword.leftView = fieldPassword;
UIView *fieldRegisterName = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_fieldRegisterName.leftViewMode = UITextFieldViewModeAlways;
_fieldRegisterName.leftView = fieldRegisterName;
UIView *fieldRegisterEmail = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_fieldRegisterEmail.leftViewMode = UITextFieldViewModeAlways;
_fieldRegisterEmail.leftView = fieldRegisterEmail;
UIView *fieldRegisterPassword = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_fieldRegisterPassword.leftViewMode = UITextFieldViewModeAlways;
_fieldRegisterPassword.leftView = fieldRegisterPassword;
我们可以创建循环或其他东西,以便这个填充可以影响我的所有文本字段吗?如何简化这个?
谢谢。答案 0 :(得分:0)
您可以继承UITextField并覆盖textRectForBounds
,editingRectForBounds
和drawPlaceholderInRect
。这已在SSToolkit SSTextField
中完成。您可以这样使用它:
textField.textEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 10)
如果要对所有文本字段使用相同的插入,则只需对此值进行子类化和编码。