我有一个带占位符文本集的UITextField。在UITextField中,我希望占位符文本为红色,并且还希望更改字体系列和幻想。
所以创建UITextField子类。我是这样写的。
-(void)drawPlaceholderInRect:(CGRect)rect
{
[[UIColor redColor]setFill];
[[self placeholder]drawInRect:rect withFont:[UIFont fontWithName:@"verdana" size:15]];
}
接下来我将此类导入我的视图控制器类。
#import "SubViewController.h"
#import "CustomUITextFieldPlaceholderAppearance.h"
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.delegate = self;
[self.view addSubview:textField];
}
然后如何更改占位符文本颜色。
答案 0 :(得分:2)
假设您的UITextField
子类为CustomUITextFieldPlaceholderAppearance
只替换你的行:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
使用:
CustomUITextFieldPlaceholderAppearance *textField = [[CustomUITextFieldPlaceholderAppearance alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
答案 1 :(得分:1)