How to set transparent background for Index Bar sections in UITableView?

How to set transparent background for sections index barin UITableView?

I tried:

tableView.sectionIndexBackgroundColor = .clearColor()

but the panel gets a light gray background

EDIT I tried to change the background color in the table, but it does not seem to be affected.

  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

I also tried color with alpha values. I can make the background translucent (see line code above). But if I set alpha to 0.0 to make it completely transparent, I will again get a light gray background.

+4
source share
2 answers

tableView.sectionIndexBackgroundColor = .clear works great here is an example

0
source

For Swift 4.2, you must set the viewBackground for your section, and for this view, set the background color.

CommonSection: UITableViewHeaderFooterView { let lightSectionColor = UIColor.gray.withAlphaComponent(0.005) (title: String, sectionColor: UIColor? = nil) {textLabel?.text = title textLabel?.fontTontFont: Uont. UIF. largeTitle)

guard let color = sectionColor else { return }

self.backgroundView = Init(value: UIView()) {
  $0.backgroundColor = color
}   } }

: Init .

0

Source: https://habr.com/ru/post/1672914/


All Articles