attributionPlaceholder字体更改

时间:2013-12-24 13:59:58

标签: ios uitextfield

我正在尝试更改占位符的字体,但是尽管出现了占位符文本,但字体是标准字体。我使用以下方法设置我的UITextField:

    UITextField *name = [[UITextField alloc] initWithFrame:CGRectMake(25, 0, frame.size.width - 50, 50)];
    name.borderStyle = UITextBorderStyleNone;
    name.background = [UIImage imageNamed:@"UITextField_orange.png"];
    name.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Name" attributes:@{NSFontAttributeName:@"Champagne&Limousines"}];;
    [self addSubview:name];

1 个答案:

答案 0 :(得分:2)

NSFontAttributeName键的值应为UIFont对象:

name.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Name" attributes: @{
  NSFontAttributeName: [UIFont fontWithName:@"Champagne&Limousines" size:12]
}];