当前位置: 首页 > news >正文

拉新接单网seo关键词推广

拉新接单网,seo关键词推广,企业网站开发语言,重庆造价工程建设信息网站需求 目的是要实现视图的自定义的渐变背景色,实现一个能够随时使用的工具。 实现讨论 在 iOS 中,如果设置视图单一的背景色,是很简单的。可是,如果要设置渐变的背景色,该怎么实现呢?其实也没有很是麻烦&…

需求

目的是要实现视图的自定义的渐变背景色,实现一个能够随时使用的工具。

实现讨论

在 iOS 中,如果设置视图单一的背景色,是很简单的。可是,如果要设置渐变的背景色,该怎么实现呢?其实也没有很是麻烦,其中使用到了 CAGradientLayer 类,只要设置好 CAGradientLayer 对象的属性,然后添加到指定视图即可。

CAGradientLayer 类

  • locations: 指定每一个渐变段的结束
  • startPoint:对应的是第一个渐变结束的点(指的是指定的颜色中,第一个颜色渐变停止的位置)
  • endPoint:对应的是最后一个渐变结束的点(指的是指定的颜色中,最后一个颜色中渐变停止的位置)
  • colors:  指定每个渐变区间的颜色

关于 locations 代码注释文档如下:

    /* An optional array of NSNumber objects defining the location of each* gradient stop as a value in the range [0,1]. The values must be* monotonically increasing. If a nil array is given, the stops are* assumed to spread uniformly across the [0,1] range. When rendered,* the colors are mapped to the output colorspace before being* interpolated. Defaults to nil. Animatable. */open var locations: [NSNumber]?

locations 中的每一个值,指定的是在渐变方向上每一个渐变停止的位置。默认为空,如果为空,则为均匀渐变。数组的大小不必和渐变区间的数量相同。

渐变的方向就是两个点连接后指向的方向。

注意这里的坐标:[0, 0] 代表的是图层的左上角,[1, 1] 代表的算是右下角。苹果的代码文档中说的是错误的,注释中的是 macOS 的坐标系统,stackoverflow 上的相关问题 https://stackoverflow.com/questions/20387803/how-to-change-cagradientlayer-color-points

    /* The start and end points of the gradient when drawn into the layer's* coordinate space. The start point corresponds to the first gradient* stop, the end point to the last gradient stop. Both points are* defined in a unit coordinate space that is then mapped to the* layer's bounds rectangle when drawn. (I.e. [0,0] is the bottom-left* corner of the layer, [1,1] is the top-right corner.) The default values* are [.5,0] and [.5,1] respectively. Both are animatable. */open var startPoint: CGPointopen var endPoint: CGPoint

示例

1 右下方向渐变

startPoint = CGPoint(x: 0, y: 0)
endPoint = CGPoint(x: 0.5, y: 0.5)
colors = [UIColor.green.cgColor, UIColor.red.cgColor]

绿色是从左上角 (0, 0) 开始渐变,红色是截止到 (0.5, 0.5) 不再渐变,右下部分的红色都是纯红色的

2. 整个视图从左上角到右下角渐变

startPoint = CGPoint(x: 0, y: 0)
endPoint = CGPoint(x: 1, y: 1)
colors = [UIColor.green.cgColor, UIColor.red.cgColor]

3. 调换颜色渐变方向

startPoint = CGPoint(x: 1, y: 1)
endPoint = CGPoint(x: 0, y: 0)
colors = [UIColor.green.cgColor, UIColor.red.cgColor]

4. 垂直渐变

startPoint = CGPoint(x: 0, y: 0)
endPoint = CGPoint(x: 0, y: 1)
colors = [UIColor.green.cgColor, UIColor.red.cgColor]

代码

    /** 设置视图渐变背景色** @param view 要设置的视图* @param frame 区域大小* @param colors 渐变颜色数组* @param horizontal 渐变方向* @param cornerRadius 圆角大小**/public static func setGradientBackgroundColor(view: UIView, frame: CGRect, colors: [CGColor], horizontal: Bool, cornerRadius: CGFloat = 0.0) -> CAGradientLayer {let startPoint = CGPoint.init(x: 0.0, y: 0.0)var endPoint = CGPoint.init(x: 1.0, y: 0.0)if horizontal == false {endPoint = CGPoint.init(x: 0.0, y: 1.0)}// 根据颜色的个数生成 locatiosvar locations: [NSNumber] = [NSNumber]()let interval = 1.0 / (Double(colors.count) - 1)for (index, _) in colors.enumerated() {locations.append(interval * Double(index) as NSNumber)}let gradientLayer: CAGradientLayer = getGradientLayer(frame: frame, startPoint: startPoint, endPoint: endPoint, locations: locations, colors: colors)gradientLayer.zPosition = -10000gradientLayer.cornerRadius = cornerRadiusview.layer.addSublayer(gradientLayer)return gradientLayer}/**** 获取一个颜色渐变层** @param frame 大小* @param startPoint 颜色渐变起点* @param endPoint 颜色渐变终点* @param locations 颜色数组对应的点* @param colors 渐变颜色数组** @return 颜色渐变层**/public static func getGradientLayer(frame: CGRect, startPoint: CGPoint, endPoint: CGPoint, locations: [NSNumber], colors: [CGColor]) -> CAGradientLayer {let gradientLayer = CAGradientLayer.init()gradientLayer.frame = framegradientLayer.startPoint = startPointgradientLayer.endPoint = endPointgradientLayer.locations = locationsgradientLayer.colors = colorsreturn gradientLayer}

http://www.hkea.cn/news/720539/

相关文章:

  • wordpress 制作下载优化关键词怎么做
  • 宁波网站建设哪个公司好百度爱采购推广怎么入驻
  • 重庆市建设工程信息网特种作业企业网站seo多少钱
  • 域名备案做电影网站制作免费个人网站
  • 公司网络营销方案优化设计七年级上册数学答案
  • 网站建设策划方案网址搜索引擎
  • 艺术培训学校系统网站怎么做百度优化是什么
  • 自己的网站做飘窗百度推广账号登录入口
  • 国内好的网站建设国内外十大免费crm软件推荐
  • 淄博品质网站建设百度销售推广
  • 网站建设学习内容网站模板哪家好
  • 建立b2b网站成本微信营销平台系统
  • 学做衣服网 缤纷网站手机百度ai入口
  • 点餐系统网站建设画质优化app下载
  • 上海都有哪些企业公司seo网站seo
  • 进一步加强政府网站建设网站建设介绍ppt
  • 做网站的设计软件上海seo推广外包
  • 中国工程局人才招聘网福建seo推广方案
  • 深圳南山做网站的公司百度投诉中心
  • 辽宁建设工程信息网业绩认定武汉网站优化公司
  • 莱芜都市人才网上海网站seo公司
  • 广州做鞋的网站怎么让某个关键词排名上去
  • 温州平阳县网站建设兼职东莞网络推广哪家公司奿
  • 做单页网站价格微信朋友圈广告在哪里做
  • 濮阳家电网站建设一般开车用什么导航最好
  • html5 图片展示网站大作设计网站
  • 河北正规网站建设比较百度一下你就知道官页
  • 企业网站建设哪家服务好福州网站关键词推广
  • 惠州悦商做网站软件开发一般需要多少钱
  • 做衣服外单网站优化大师官方正版下载