我尝试设置导航标题和其他项目的fontsize。 我怎么能这样做?
我们可以通过方法uinavigationbar.setTitleTextAttributes设置这个方法,但是这个方法不再存在(
)有人知道该怎么做吗?
navigationBar = UINavigationBar(frame: CGRectMake(0, 0, fDialogWidth, navbarHeigth))
let navigationItem = UINavigationItem()
navigationItem.title = sTitle;
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: sBacklabel, style: UIBarButtonItemStyle.Plain, target: self, action: "backAction:")
let rightButton = UIBarButtonItem(title: saddBookmark, style: UIBarButtonItemStyle.Plain, target: self, action: "addBookmarkAction:")
// Create two buttons for the navigation item
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
navigationBar.items = [navigationItem];
navigationBar.frame = CGRectMake(0, 0, screenwidth, navbarHeigth);
答案 0 :(得分:12)
将这些行添加到viewDidLoad()
方法中:
self.navigationController?.navigationBar.topItem?.title = "Your title"
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Your Font", size: 34)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
答案 1 :(得分:2)
试试这个......
let titleAttributes = [
NSFontAttributeName: UIFont(name: "your font name", size: 15)!
]
self.navigationController?.navigationBar.titleTextAttributes = titleAttributes
如果您使用的是系统字体
let titleAttributes = [
NSFontAttributeName: UIFont.systemFontOfSize(15)
]
self.navigationController?.navigationBar.titleTextAttributes = titleAttributes