我想知道如何更改BarButtonItem
的文字字体?虽然我无法设置setTitleTextAttributes
class TextfieldLogin : UITextField {
func INIT(){
let numberToolbar = UIToolbar(frame: CGRectMake(0,0,320,50))
numberToolbar.tintColor = UIColor.whiteColor()
numberToolbar.barTintColor = UIColor(red: 155.0/255, green: 14.0/255, blue: 45.0/255, alpha: 1.0)
numberToolbar.items = [
UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil),
UIBarButtonItem(title: "DONE", style: UIBarButtonItemStyle.Plain, target: self, action: "close"),
UIBarButtonItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(18.0),NSForegroundColorAttributeName : UIColor.redColor(),NSBackgroundColorAttributeName:UIColor.blackColor()],
forState: UIControlState.Normal) ]
numberToolbar.sizeToFit()
}
}
答案 0 :(得分:12)
这是你想要的吗?
目标-C:
[buttonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica-Bold" size:20.0], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
夫特:
let titleDict: NSDictionary = [NSFontAttributeName: "Helvetica-Bold"]
self.numberToolbar.titleTextAttributes = titleDict
答案 1 :(得分:3)
与所有UIBarItem
一样,您可以使用以下方式设置文字属性:
- (void)setTitleTextAttributes:(NSDictionary *)attributes
forState:(UIControlState)state
您还可以使用tintColor
更改文字颜色。
我建议坚持使用Apple的样式指南,只在done
项目上使用粗体字。