iOS - UIView操作(SWift)
Posted PureWind
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS - UIView操作(SWift)相关的知识,希望对你有一定的参考价值。
1. UIView 视图的渐变填充
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//渐变填充色的图形
let rect = CGRect(x: 30, y: 60, width: 200, height: 200)
let gradientView = UIView(frame: rect)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = gradientView.frame
let fromColor = UIColor.yellowColor().CGColor
let midColor = UIColor.redColor().CGColor
let toColor = UIColor.purpleColor().CGColor
gradientLayer.colors = [fromColor,midColor,toColor]
//将设置好的渐变层,添加到视图对象的层中.
view.layer.addSublayer(gradientLayer)
//将视图对象,添加到当前视图控制器的根视图
self.view.addSubview(gradientView)
}
2. UIView视图的纹理
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//将导入的图片作为纹理,平铺整个屏幕
let image = UIImage(named: "Sample")
//新建颜色对象,将导入的图片赋予该对象
let patternColor = UIColor.init(patternImage: image!)
self.view.backgroundColor = patternColor
}
持续更新中...
以上是关于iOS - UIView操作(SWift)的主要内容,如果未能解决你的问题,请参考以下文章
在 Swift 中创建自定义 UIView 并显示为弹出窗口