我们可以到Switch开启时背景色会是绿色,关掉时却是黑色,这样其实跟原本IPhone内建的也不一样,
这样眼睛看上去也不直观,因此来帮他加个背景色吧!
不就加个背景色而已吗?看我一行程序码搞定他
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.backgroundColor = .clear
// 设定accessoryView 为 UISwitch
self.accessoryView = UISwitch(frame: .zero)
// 设定accessoryView 背景色为 灰色
self.accessoryView?.backgroundColor = .gray
setViews()
setLayouts()
}
执行看看吧!
居然是整个正方形的背景色都变成灰色了,看来只好自己做出一个UISwitch了!
CornerRadius是让正方体的边边变圆弧的参数,数字越大越圆
let accessorySwitch: UISwitch = {
let uiSwitch = UISwitch(frame: .zero)
// 设定 Switch 的背景色为灰色
uiSwitch.backgroundColor = .lightGray
// 设定 Switch 的 CornerRadius
// CornerRadius 设为高度的一半,边边就会变成圆形
uiSwitch.layer.cornerRadius = uiSwitch.frame.height / 2.0
return uiSwitch
}()
2.之後到init里面更改AccessoryView,更改为我们刚刚制作的UISWitch
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.backgroundColor = .clear
// 设定accessoryView 为 我们制作的UISwitch
self.accessoryView = accessorySwitch
setViews()
setLayouts()
}
再执行看看吧!
<<: 学习Python纪录Day21 - 用Python处理Excel
Python非同步需要使用到asyncio,简单测试如下 import asyncio import...
今天我们从 TLB 出发,来看看可以复习多少计算机组织架构的知识! 从 TLB 是什麽出发 TLB(...
以下针对这次的 乔叔带你上手 Elastic Stack - 探索与实践 Observability...
网站+网页绪论 浏览器介绍(推Firefox跟Edge) 上图取自台科大资安社课教材 浏览网页发生的...
在 [Day 20],[Day 21],[Day 22] 介绍了「Edge Impulse + BL...