CAN*_*CAN 6 uibarbuttonitem ios swift
我想知道如何更改文本字体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()
}
}
Run Code Online (Sandbox Code Playgroud)
MSU*_*dog 12
这是你在找什么?
Objective-C的:
[buttonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica-Bold" size:20.0], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
迅速:
let titleDict: NSDictionary = [NSFontAttributeName: "Helvetica-Bold"]
self.numberToolbar.titleTextAttributes = titleDict
Run Code Online (Sandbox Code Playgroud)
与 all 一样UIBarItem,您可以使用以下方法设置文本属性:
- (void)setTitleTextAttributes:(NSDictionary *)attributes
forState:(UIControlState)state
Run Code Online (Sandbox Code Playgroud)
您还可以用来tintColor更改文本颜色。
我建议遵循苹果的风格指南,仅在该done项目上使用粗体字体。
| 归档时间: |
|
| 查看次数: |
14426 次 |
| 最近记录: |