码迷,mamicode.com
首页 > 移动开发 > 详细

iOS - UIView操作(SWift)

时间:2016-11-19 03:09:51      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:pat   图形   name   视图控制器   layer   override   渐变   die   from   

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)

标签:pat   图形   name   视图控制器   layer   override   渐变   die   from   

原文地址:http://www.cnblogs.com/share-iOS/p/6079554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!