如何在swift中插入子图层?

前端之家收集整理的这篇文章主要介绍了如何在swift中插入子图层?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个视图并为其添加渐变图层.

我有这个:

import UIKit
import QuartzCore


let rect : CGRect = CGRectMake(0,320,100)

var vista : UIView = init(frame: rect)

let gradient : CAGradientLayer = CAGradientLayer()
gradient.frame = vista.bounds

let cor1 = UIColor.blackColor().CGColor
let cor2 = UIColor.whiteColor().CGColor

let arrayColors = [cor1,cor2]

gradient.colors = arrayColors

现在我必须这样做

[view.layer insertSublayer:gradient atIndex:0];

我如何在swift中做到这一点?

您可以使用以下代码
view.layer.insertSublayer(yourLayer,atIndex: yourIndex)
原文链接:https://www.f2er.com/swift/319026.html

猜你在找的Swift相关文章