首页 > 代码库 > iOS - UIView操作(SWift)

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)