当前位置:网站首页>Swift 之返回按钮
Swift 之返回按钮
2022-06-21 10:49:00 【生来如风】
1、左侧图标+文字

private lazy var backButton: UIButton = {
let button = UIButton()
button.setImage(ImageLoader.image(named: "back"), for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: -16)
button.setTitle(NSLocalizedString("SETTINGS", comment: ""), for: .normal)
button.addTarget(self, action: #selector(backOnTapped), for: .touchUpInside)
button.setTitleColor(.mainTextColor, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 18.0)
return button
}()
2、左侧返回图标,标题居中

public override func viewDidLoad() {
...
navigationItem.titleView = titleView
navigationController?.navigationBar.topItem?.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
...
}
private lazy var titleView: UILabel = {
let label = UILabel()
label.text = NSLocalizedString("Add Friend", comment: "Add friend")
label.textColor = .mainTextColor
label.font = .systemFont(ofSize: 18.0)
return label
}()
边栏推荐
- Detailed explanation of connection pool parameter settings (view while adjusting)
- 文旅新体验!3DCAT助力广州非遗“元宇宙”街区炫酷亮相
- MySQL - Database Foundation
- cvte一面
- Actual measurement: the performance of cloud RDS MySQL is 1.6 times that of self built
- Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?
- New programmers optimize a line of code on Monday and are discouraged on Wednesday?
- TensorFlow,危!抛弃者正是谷歌自己
- 15+城市道路要素分割应用,用这一个分割模型就够了!
- Positive results of enx-101 clinical 1b study published by English topics
猜你喜欢

The most powerful eight part essay in 2022, "code out eight part essay - cut out the offer line"

03. Redis actual battle: meeting goddess nearby by geo type

Simple Android weather app (III) -- city management and database operation

06. Redis log: the trump card for fast recovery without fear of downtime

Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?

China international e-commerce center and Analysys jointly released: the national online retail development index in the fourth quarter of 2021 increased by 0.6% year on year

The backbone of the top 100 security companies! Meichuang technology was selected into the 2022 China top 100 Digital Security Report
![Fastapi web framework [pydantic]](/img/e1/290a8a6a978b9fb56a9c86f1734c45.png)
Fastapi web framework [pydantic]

Citus 11 for Postgres 完全开源,可从任何节点查询(Citus 官方博客)

02. Redis Blockbuster: viewing core principles from high-frequency problems
随机推荐
grant all privileges on
MySQL - library operation
Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?
Software architecture discussion
Application configuration management, basic principle analysis
Running view of program
【obs】libobs_winrt.dll
Matplotlib 绘制圆环图的两种方法!
2022年最强八股文《码出八股文-斩出offer线》
在国外当程序员到底爽不爽?
wangeditor封装插件初步
【zz】owt-server:音视频转发示意图
Starting a prairie fire, Alibaba cloud database "hundred cities gather together" to help small and medium-sized enterprises' digital intelligence transformation
Solon 1.8.3 发布,云原生微服务开发框架
知识点滴 - 什么是加速移动网页(AMP)?
WPF DataContext usage
The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised
06. Redis log: the trump card for fast recovery without fear of downtime
触摸按键控制器TTP229-BSF使用心得[原创cnblogs.com/helesheng]
DSP online upgrade (3) -- how to burn two projects in the on-chip flash of a DSP chip