我有自定义UITextField类别,用于为整个应用程序自定义UITextField外观。但有时我需要禁用字段语句,并使用自定义设计看起来灰暗。
Like to have custom [_myUITextfield setDisabled];
并且setDisabled具有
enabled = NO;
backgroundColor = [UIColor lightGrayColor];
textColor = [UIColor grayColor];
我尝试添加类方法,但无法访问自己。
我现在所拥有的是定制设计:
CutomTextField.h
@interface CustomTextField : UITextField
@end
CutomTextField.m
@implementation CustomTextField
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
self.borderStyle = UITextBorderStyleNone;
[self.layer setBackgroundColor:[[UIColor whiteColor] CGColor]];
[self.layer setBorderColor: [[UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1.0] CGColor]];
[self.layer setBorderWidth: 0.0];
[self.layer setShadowOpacity:1.0];
[self.layer setShadowColor:[[UIColor colorWithRed:122/255.0 green:122/255.0 blue:122/255.0 alpha:1.0] CGColor]];
[self.layer setShadowRadius:1.0];
[self.layer setShadowOffset:CGSizeMake(0, 1)];
self.layer.masksToBounds = NO;
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
self.leftView = paddingView;
self.leftViewMode = UITextFieldViewModeAlways;
}
return self;
}
@end
谢谢!