Walker Walker - 1 year ago 256
Swift Question

swift - change color of top UIToolbar border

I'm trying to change the color of the top border on a UIToolbar.

I tried:

layer.borderWidth = 1
layer.borderColor = UIColor(r: 250, g: 250, b: 250).CGColor

That didn't work.

Suggestions? Thank you

Answer Source

I've done it using this code:

class ViewController: UIViewController {

  @IBOutlet weak var toolBar: UIToolbar!

  override func viewDidLoad() {

    // the layer with the width of the device
    // and height of 0.5 px
    let topBorder = CALayer()
    topBorder.frame = CGRectMake(0, 0, view.frame.size.width, 0.5)
    topBorder.backgroundColor = UIColor.redColor().CGColor

    // adding the layer to the top
    // of the toolBar


enter image description here

Source: https://blog.adamcooke.io/set-the-top-border-colour-of-a-uinavbar-d9035c6b4fdb#.f37molpsj

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download