外部设置UINavigation 的 Title 和 barbu
2016-09-06 本文已影响85人
童冀
功能简单,不想新写个控制器,直接设置navigation的标题和返回按钮,可以用此方法设置
let contro = UIViewController()
@IBAction func goAgreement(sender: AnyObject) {
let webView = UIWebView(frame: UIScreen.mainScreen().bounds)
webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("agreement", withExtension: "html")!))
contro.view.addSubview(webView)
let navi = UINavigationController(rootViewController: contro)
navi.navigationBar.topItem!.title = "用户协议"
navi.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.redColor()]
navi.navigationBar.topItem?.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "icon_back")?.imageWithRenderingMode(.AlwaysOriginal), style: .Plain, target: self, action: #selector(LoginViewController.backToRegistView))
presentViewController(navi, animated: true) {
}
}
func backToRegistView() {
contro.dismissViewControllerAnimated(true) {
}
}
苹果的解释重点是用上topItem进行设置