美文网首页
如何改变UITableViewCell的选中样式(颜色)?sto

如何改变UITableViewCell的选中样式(颜色)?sto

作者: Lebus | 来源:发表于2019-05-09 22:11 被阅读0次

想要改变cell被选中后的颜色,看到storyboard上有个selection,很兴奋,改一下蓝色试试,结果不管用。。


屏幕快照 2019-05-09 下午2.19.20.png

原因:

https://developer.apple.com/documentation/uikit/uitableviewcell/selectionstyle/blue

官方说了,这个已经废弃了,还放在这里可能只是遗留兼容问题。

正确姿势:

UITableViewControllercellForRowAt里面:

let selectedView = UIView()
selectedView.backgroundColor = UIColor.blue
cell.selectedBackgroundView = selectedView

在自定义的UITableViewCellawakeFromNib函数里面:

let selectedView = UIView()
selectedView.backgroundColor = UIColor.blue
selectedBackgroundView = selectedView

特别提醒:过多的自定义cell的样式会影响到tableview的滑动性能。

 

广告时间:小弟的iOS12零基础视频教程(每章皆可试听):

http://m.study.163.com/provider/480000001852411/index.htm?share=2&shareId=480000001852411

相关文章

网友评论

      本文标题:如何改变UITableViewCell的选中样式(颜色)?sto

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