-3
A
回答
0
你是什么意思是添加“渐变”效果到你的UIView。为此,您需要添加CAGradientLayer,您可以创建类似于此的自定义UIView
:
class CustomView: UIView {
private let gradientLayer = CAGradientLayer()
override func awakeFromNib() {
super.awakeFromNib()
addGradient()
}
override func layoutSubviews() {
super.layoutSubviews()
// update gradient
gradientLayer.frame = self.bounds
}
private func addGradient() {
// declaring colors for your gradient:
// top color is clear
let topColor = UIColor.clear.cgColor
// bottom color is black
let bottomColor = UIColor.black.cgColor
gradientLayer.frame = self.frame
// add colors to the gradientLayer:
gradientLayer.colors = [topColor, bottomColor]
// change the startPoint and endPoint to make it appears like it should...
gradientLayer.startPoint = CGPoint(x: 1.0, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0)
// add the gradient to your view (which in my case is gradientView)
self.layer.insertSublayer(gradientLayer, at: 0)
}
}
相关问题
- 1. 从顶部滚动时淡入淡出背景颜色
- 2. jQuery在背景颜色淡入淡出
- 3. 如何淡入淡出svg的颜色
- 4. 淡入淡出我的页面顶部
- 5. 用UIViewView的顶部淡入UIView部分
- 6. uiview屏幕淡入淡出
- 7. 使新颜色淡入淡出
- 8. 通过颜色淡入淡出
- 9. 多个颜色淡入淡出
- 10. 淡入淡出文字链接颜色
- 11. 淡出在页面顶部,淡入底部
- 12. 淡入淡出底部或顶部的文本
- 13. 如何在Java中绘制淡入淡出的颜色?
- 14. 在jPanel顶部的图像中淡入淡出
- 15. jQuery - 淡入淡出之后点击外部,淡入淡出
- 16. 淡入淡出的背景图像(不是正文或淡出背景颜色)
- 17. 添加淡入淡出顶端
- 18. C++淡入颜色? (Arduino的)
- 19. 淡入淡入时,淡入淡出时只有底部可见
- 20. jQuery的淡入淡出的CSS背景图像和颜色
- 21. jQuery淡入淡出的标题栏的背景颜色
- 22. 有条件的图形和淡入淡出的颜色
- 23. 更改带淡入淡出效果的背景颜色
- 24. JavaScript的背景颜色淡入淡出RGB算法问题
- 25. 与Jquery悬停的菜单颜色淡入淡出
- 26. 对链接颜色的淡入淡出效果
- 27. GWT FlexTable中单元格颜色的淡入淡出
- 28. 淡入/淡出wxpython网格单元格的背景颜色
- 29. 如何使线图中的颜色淡入淡出matplotlib和python
- 30. 淡出UIView?