【发布时间】:2015-12-29 06:21:50
【问题描述】:
我有一个带有占位符文本集的 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];
}
那么如何改变占位符的文字颜色。
【问题讨论】:
标签: ios objective-c iphone xcode