【问题标题】:Why does the font of my UITextField change when editing?为什么我的 UITextField 的字体在编辑时会改变?
【发布时间】: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


【解决方案1】:

检查了您的代码.... 并且只有一个词表示该 WTF....!
我不知道这有什么问题,但有一个解决方案,它是

self.nameTextField.font = [UIFont fontWithName:@"Courier New" size:21];


只需更改字体名称。这会起作用..干杯:)
顺便说一句,您可能发现了一个错误,或者可能不是这就是苹果添加“Courier New”的原因。
我不知道...

【讨论】:

  • 哈,我一度以为“WTF”指的是我的编码质量!无论如何,正如您所建议的,更改字体有效。谢谢!
  • 我遇到了同样的问题,但不知道为什么会这样。我正在使用 Avenir Next 字体。
  • @S.J 我真的不知道为什么会这样,我可以使用其他字体或者只是提交错误@bugreport.apple.com
猜你喜欢
  • 2012-03-10
  • 2015-04-11
  • 1970-01-01
  • 2016-01-03
  • 2021-12-20
  • 1970-01-01
  • 1970-01-01
  • 2021-01-28
  • 1970-01-01
相关资源
最近更新 更多