我正在尝试更改 UIToolbar 上边框的颜色。
我试过:
layer.borderWidth = 1
layer.borderColor = UIColor(r: 250, g: 250, b: 250).CGColor
Run Code Online (Sandbox Code Playgroud)
那行不通。
建议?谢谢
我已经使用这段代码完成了:
class ViewController: UIViewController {
@IBOutlet weak var toolBar: UIToolbar!
override func viewDidLoad() {
super.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
toolBar.layer.addSublayer(topBorder)
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
来源:https ://blog.adamcooke.io/set-the-top-border-colour-of-a-uinavbar-d9035c6b4fdb#.f37molpsj
| 归档时间: |
|
| 查看次数: |
2524 次 |
| 最近记录: |