美文网首页
外部设置UINavigation 的 Title 和 barbu

外部设置UINavigation 的 Title 和 barbu

作者: 童冀 | 来源:发表于2016-09-06 14:21 被阅读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进行设置

苹果的解释

相关文章

网友评论

      本文标题:外部设置UINavigation 的 Title 和 barbu

      本文链接:https://www.haomeiwen.com/subject/lwudettx.html