swift中UINavigationController的使用
来源:互联网 发布:知乎 电脑下载 编辑:程序博客网 时间:2024/05/18 18:17
// 导航视图控制器标题self.navigationItem.title = "navigationController" // 导航视图控制器样式self.navigationController!.setNavigationStyleDefault() // 导航视图控制器左按钮self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "present", style: UIBarButtonItemStyle.Done, target: self, action: Selector("presentClick"))self.navigationItem.leftBarButtonItem!.tintColor = UIColor.greenColor() // 导航视图控制器右按钮self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "push", style: UIBarButtonItemStyle.Done, target: self, action: Selector("pushClick"))self.navigationItem.rightBarButtonItem!.tintColor = UIColor.orangeColor()
// 注意:如果下个视图控制器的导航栏样式与当前的不一样时,返回当前视图控制器时,需要重置下样式override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) // 导航视图控制器样式 self.navigationController!.setNavigationStyleDefault()}
// 导航视图控制器样式self.navigationController!.setNavigationStyle(UIColor.orangeColor(), textFont: UIFont.boldSystemFontOfSize(12.0), textColor: UIColor.yellowColor())
// 导航栏隐藏,或显示let button = UIButton(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.view.frame) - 10.0 * 2), 40.0))self.view.addSubview(button)button.backgroundColor = UIColor.lightGrayColor()button.setTitle("隐藏导航栏", forState: UIControlState.Normal)button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)button.setTitleColor(UIColor.redColor(), forState: UIControlState.Highlighted)button.addTarget(self, action: Selector("hiddenClick:"), forControlEvents: UIControlEvents.TouchUpInside)button.selected = false
func hiddenClick(button:UIButton){ button.selected = !button.selected let isSelected = button.selected let text = (isSelected ? "隐藏" : "显示") print("\(text) 导航栏") if isSelected { button.setTitle("显示导航栏", forState: UIControlState.Normal) self.navigationController!.setNavigationBarHidden(true, animated: true) } else { button.setTitle("隐藏导航栏", forState: UIControlState.Normal) self.navigationController!.setNavigationBarHidden(false, animated: true) } }
// 导航栏样式设置方法// MARK: - 导航栏样式设置/// 设置默认导航栏样式func setNavigationStyleDefault(){ self.setNavigationStyle(UIColor.whiteColor(), textFont: UIFont.boldSystemFontOfSize(18.0), textColor: UIColor.blackColor())} /// 导航栏样式设置(自定义背景颜色、字体)func setNavigationStyle(backgroundColor:UIColor, textFont:UIFont, textColor:UIColor){ if self.navigationBar.respondsToSelector(Selector("barTintColor")) { // 背景色 self.navigationBar.barTintColor = backgroundColor self.navigationBar.translucent = false self.navigationBar.tintColor = UIColor.whiteColor() // 字体 self.navigationBar.titleTextAttributes = [NSFontAttributeName:textFont, NSForegroundColorAttributeName:textColor]; // 导航底部1px的阴影颜色-修改 /* self.navigationBar.shadowImage = UIImage(named: "") [self.navigationBar setShadowImage:kImageWithColor(kColorSeparatorline)]; */ // 导航底部1px的阴影-遮住 let maskLayer = CAShapeLayer.init() maskLayer.backgroundColor = UIColor.redColor().CGColor; let maskRect = CGRectMake(0, -20.0, CGRectGetWidth(self.navigationBar.frame), (20.0 + CGRectGetHeight(self.navigationBar.frame))); maskLayer.path = CGPathCreateWithRect(maskRect, nil); self.navigationBar.layer.mask = maskLayer; }}
源码:https://github.com/potato512/SYSwiftLearning
0 0
- swift中UINavigationController的使用
- Swift 中UIWebView 和 UINavigationController的应用
- iOS中导航控制器的使用 UINavigationController
- Swift--UINavigationController
- UINavigationController的使用
- UINavigationController的使用技巧
- UINavigationController的使用
- UiNavigationController的使用
- UINavigationController,UITableview的使用
- UINavigationController的使用
- UINavigationController 的使用
- IOS的UINavigationController使用
- 在presentModalViewController中使用UINavigationController
- 在presentModalViewController中使用UINavigationController
- UINavigationController 及使用中遇到的问题总结
- swift中代理的使用
- swift中通知的使用
- Swift中UIAlertController的使用
- 链式队列定义以及应用
- 常用性能分析工具之sar、iostat
- Bakery Algorithm的c#实现用于多线程互斥访问临界资源
- Linux命令发送Http的get或post请求(curl和wget两种方法)
- 文件默认权限
- swift中UINavigationController的使用
- java 原码、反码、补码计算 以及 取反(~)运算
- 低电压检测
- P1309瑞士轮
- 14.4.1 Buffer Pool
- Android Studio错误: 非法字符: '\ufeff' 需要class, interface或enum
- Java Web中遇到中文编码乱码问题
- 解决Windows用vnc连接Ubuntu时出现The connection was refused by the host computer问题
- 【JS】实现单选框的左右移动