let bottomBorder = CALayer()
bottomBorder.backgroundColor = UIColor.viewShadowGray().cgColor
bottomBorder.frame = CGRect(x: 0, y: view.frame.size.height - 1, width: view.frame.size.width, height: 1)
view.layer.addSublayer(bottomBorder)
答案 0 :(得分:2)
使用CAGradientLayer
:
let gradientLayer = CAGradientLayer()
gradientLayer.frame = CGRect(x: 0, y: view.frame.size.height - 1, width: view.frame.size.width, height: 1)
gradientLayer.colors = [
UIColor.white.withAlphaComponent(0.5).cgColor,
UIColor.white.withAlphaComponent(0.0).cgColor
]
view.layer.addSublayer(gradientLayer)
根据需要调整渐变颜色。