【发布时间】:2011-05-11 10:15:26
【问题描述】:
我的 UITextField 的字体在编辑时会变浅,而在编辑完成时会变粗。这些图片应该能说明问题:
谁能解释这是为什么,以及如何阻止它?
这是我为它准备的所有代码 - 首先是我的 UITextField 子类(它只是用来添加边距):
@interface RLTextField : UITextField {
}
@end
@implementation RLTextField
- (CGRect)editingRectForBounds:(CGRect)bounds
{
CGRect editingRect = CGRectMake(bounds.origin.x+35, bounds.origin.y-5, bounds.size.width, bounds.size.height);
return editingRect;
}
- (CGRect)textRectForBounds:(CGRect)bounds
{
CGRect editingRect = CGRectMake(bounds.origin.x+35, bounds.origin.y-5, bounds.size.width, bounds.size.height);
return editingRect;
}
@end
然后将它实际添加到我的 viewController 中:
- (void)viewDidLoad
{
CGRect noteTitleTextFrame = CGRectMake(self.view.bounds.origin.x,
self.view.bounds.origin.y+10,
self.view.bounds.size.width,
44);
RLTextField *textField = [[RLTextField alloc] initWithFrame:noteTitleTextFrame];
self.nameTextField = textField; [textField release];
self.nameTextField.delegate = self;
self.nameTextField.borderStyle = UITextBorderStyleNone;
self.nameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
self.nameTextField.font = [UIFont fontWithName:@"Courier" size:21];
[self.view addSubview:self.nameTextField];
}
【问题讨论】:
-
我可以知道 RLTextField 是什么意思吗?
-
这只是我的 UITextField 的子类 - 我在上面添加了 @interface 以使其更清晰。
标签: iphone cocoa-touch uitextfield