Manually drawing a gradient in iPhone apps?

后端 未结 7 1224
一个人的身影
一个人的身影 2020-12-28 20:53

If I have two UIColors, what\'s the best way to draw an even gradient between them over an arbitrarily-sized area?

I am guessing you would create a UIView subclass a

7条回答
  •  时光说笑
    2020-12-28 21:33

    The Swift way to add Gradient is :

        var view : UIView = UIView(frame: CGRectMake(0, 0, 320, 100))
        var g : CAGradientLayer = CAGradientLayer()
        g.frame = gradientView.bounds
        g.colors = ["000000".UIColor.CGColor , "111111".UIColor.CGColor]
        view.layer.insertSublayer(g, atIndex: 0)
    

    UIColor() is a helper class for Swift to convert hex color to rgb color, highly recommended.

提交回复
热议问题