[英]How do I set a transparent background for the sections Index Bar in a UITableView?
如何在UITableView
为sections index bar
设置透明背景?
我试过了:
tableView.sectionIndexBackgroundColor = .clearColor()
但酒吧的背景为浅灰色
编辑我试图改变tableview的背景颜色,但它似乎没有影响。
tableView.backgroundView = UIView.init()
tableView.backgroundColor = .blackColor() // tried .clearColor() too.
EDIT2
tableView.sectionIndexBackgroundColor = UIColor(white: CGFloat(1.0), alpha: CGFloat(0.5)) // change the alpha and check once
我也尝试过使用alpha值的颜色。 我可以使背景半透明(参见上面的行代码)。 但是,如果我将alpha设置为0.0以使其完全透明,我将再次获得浅灰色背景。
对于swift 4.2,您必须为您的部分设置viewBackground,并为该视图设置背景颜色。
class CommonSection:UITableViewHeaderFooterView {static let lightSectionColor = UIColor.gray.withAlphaComponent(0.005)func setup(title:String,sectionColor:UIColor?= nil){textLabel?.text = title textLabel?.font = UIFont.preferredFont(forTextStyle :. largeTitle)
guard let color = sectionColor else { return } self.backgroundView = Init(value: UIView()) { $0.backgroundColor = color } } }
注意:Init只是初始化元素的快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.