我想更改导航控制器的文字和字体。
我有一个静态UITableView
,当用户点击一个单元格时 - 我通过segue转到第二个UIViewController。
我在故事板和我的代码中设置了segue的名称:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "myTestSegue") {
if segue.destination is MyTest {
print("can I see it?")
let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: nil)
backButton.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "AppleSDGothicNeo-Light", size: 20.0)!], for: UIControlState())
navigationItem.backBarButtonItem = backButton
}
}
}
现在,当我运行应用程序并单击单元格时,我在控制台中看到:can I see it?
,但下一个面板上按钮的文本和字体不会改变。
我错过了什么?
答案 0 :(得分:2)
您可以使用此代码更改后退按钮的字体样式。
CREATE TABLE `couriers` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(255) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE `orders` ( `id` INT NOT NULL AUTO_INCREMENT , `courier_id` INT NULL , `product_id` INT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `orders` ADD INDEX(`courier_id`);
ALTER TABLE `orders` ADD CONSTRAINT `fk_courier` FOREIGN KEY (`courier_id`) REFERENCES `couriers`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
答案 1 :(得分:0)
试试这段代码;
let customFont = UIFont(name: "Your font Name", size: 17.0)
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFont!], for: UIControlState.normal)