Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift 快速奔跑的兔几 本节的内容是:绘画第二讲~大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

绘制阴影的栗子: 注意需要保存和恢复上下文,否则画布上所有的绘制图形都会加上阴影。 // shadow let context = UIGraphicsGetCurrentContext() let shadowRect = CGRecTinset(self.bounds, self.bounds.size.width*0.1, self.bounds.size.

绘制阴影的栗子:
注意需要保存和恢复上下文,否则画布上所有的绘制图形都会加上阴影。

// shadow
        let context = UIGraphicsGetCurrentContext()

        let shadowRect = CGRecTinset(self.bounds,self.bounds.size.width*0.1,self.bounds.size.height*0.1)

        let shadowPath = UIBezierPath(roundedRect: shadowRect,cornerRadius: 10)

        CGContextSaveGState(context)

        let shadowStyle = UIColor.blueColor().CGColor
        let shadowOffset = CGSize(width: 3,height: 3)
        let shadowBlurRadius:CGFloat = 5.0

        CGContextSetShadowWithColor(context,shadowOffset,shadowBlurRadius,shadowStylE)

        UIColor.grayColor().setFill()
        shadowPath.fill()

        CGContextRestoreGState(context)

下面是渐变的栗子:

let colorSpace = CGColorSpaceCreateDeviceRGB()

        let context = UIGraphicsGetCurrentContext()

        let gradientStartColor = UIColor(red: 0.1,green: 0.1,blue: 0.8,alpha: 1)
        let gradientEndColor = UIColor(red: 1,green: 0.6,alpha: 1)

        let gradientColors:CFArray = [gradientStartColor.CGColor,gradientEndColor.CGColor]
        let gradientLOCATIOns:[CGFloat] = [0.0,1.0]

        let gradients = CGGradientCreateWithColors(colorSpace,gradientColors,gradientLOCATIOns)

        let pathRect = CGRecTinset(self.bounds,20,20)

        let topPoint = CGPointMake(self.bounds.size.width/2,20)
        let bottomPoint = CGPointMake(self.bounds.size.width/2,self.bounds.size.height - 20)

        let roundedRectPath = UIBezierPath(roundedRect: pathRect,cornerRadius: 4)

        CGContextSaveGState(context)
        roundedRectPath.addClip()
        CGContextDrawLinearGradient(context,gradients,bottomPoint,topPoint,CGGradientDrawingOptions.DrawsAfterEndLOCATIOn)
        CGContextRestoreGState(context)

大佬总结

以上是大佬教程为你收集整理的swift 快速奔跑的兔几 本节的内容是:绘画第二讲~全部内容,希望文章能够帮你解决swift 快速奔跑的兔几 本节的内容是:绘画第二讲~所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。