swift navigationItem titleButton
来源:互联网 发布:淘宝新店0销量 编辑:程序博客网 时间:2024/05/21 06:57
titleButton是系统不能满足需求而且自己封装的button。
import UIKitclass TitleButton: UIButton { override init(frame : CGRect) { super.init(frame: frame) setImage(UIImage(named: "tabbar_discover"), for: .normal) setImage(UIImage(named: "tabbar_discover_selected"), for: .selected) setTitleColor(UIColor.black, for: .normal) sizeToFit() } // 必须实现 required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() titleLabel!.frame.origin.x = 0 imageView!.frame.origin.x = titleLabel!.frame.size.width + 5 }}
创建好titleButton之后使用titleButton
let titleBtn : TitleButton = TitleButton() titleBtn.setTitle("txwDemo", for: .normal) titleBtn.addTarget(self, action: #selector(OneVC.titleBtnClick), for: .touchUpInside) navigationItem.titleView = titleBtn
// 监听标题按钮点击extension OneVC { func titleBtnClick(titleBtn :TitleButton){ // 改变按钮状态 titleBtn.isSelected = !titleBtn.isSelected // let vc = UIViewController() self.present(vc, animated: true, completion: nil) }}
0 0
- swift navigationItem titleButton
- TitleButton
- 【新浪微博项目】07--设置navigationItem和自定义TitleButton
- iOS - Swift 设置navigationItem
- swift navigationItem封装
- Swift 设置navigationitem
- Swift navigationItem 属性常用设置
- swift 修改navigationItem.title的颜色
- navigationItem
- navigationItem
- swift语言IOS8开发战记18 NavigationItem
- navigationItem.hidesBackButton
- 关于navigationItem
- 添加navigationItem
- 导航navigationItem
- iOS-navigationItem
- navigationitem 的titleView
- 关于NavigationItem.rightBarButtonItem设置
- 编程总结(二)C++11中的多线程
- input标签type="file"的格式要求,以及文件阅读,图片上传前的显示
- Spring Redis(2)数据访问
- 2017华为机试题--投骰子问题
- 将博客搬至CSDN
- swift navigationItem titleButton
- 栈模拟进制转化
- 双亲加载模式
- 操作系统实验四之实现shell
- classic bluetooth chat 三
- Apache Maven 入门篇(下)
- 什么是java REST与RESTFUL
- oracle 创建数据表空间和用户
- Spring MVC controller间跳转 重定向 传参