加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在swift中插入子图层?

发布时间:2020-12-14 05:23:22 所属栏目:百科 来源:网络整理
导读:我正在创建一个视图并为其添加渐变图层. 我有这个: import UIKitimport QuartzCorelet rect : CGRect = CGRectMake(0,320,100)var vista : UIView = init(frame: rect)let gradient : CAGradientLayer = CAGradientLayer()gradient.frame = vista.boundslet
我正在创建一个视图并为其添加渐变图层.

我有这个:

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读