CGColorSpaceCreateDeviceRGB()

简介: <pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; line-height:18px; background-color:rgb(245,245,245); font-family:'Courier New'!important"><s
//绘制背景渐变

    /*

     CGCradientCreateWithColorComponents函数需要四个参数:

     色彩空间:(Color Space)这是一个色彩范围的容器,类型必须是CGColorSpaceRef.对于这个参数,我们可以传入CGColorSpaceCreateDeviceRGB函数的返回值,它将给我们一个RGB色彩空间。

     颜色分量的数组:这个数组必须包含CGFloat类型的红、绿、蓝和alpha值。数组中元素的数量和接下来两个参数密切。从本质来讲,你必须让这个数组包含足够的值,用来指定第四个参数中位置的数量。所以如果你需要两个位置位置(起点和终点),那么你必须为数组提供两种颜色

     位置数组,颜色数组中各个颜色的位置:此参数控制该渐变从一种颜色过渡到另一种颜色的速度有多快。

     位置的数量:这个参数指明了我们需要多少颜色和位置。

     */

    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();

    CGFloat colors[] =

    {

        51.0 / 255.0, 160.0 / 255.0, 0.0 / 255.0, 1.00,

        68.0 / 255.0, 198.0 / 255.0, 0.0 / 255.0, 1.00,

//        0.0 / 255.0,  50.0 / 255.0, 126.0 / 255.0, 1.00,

    };

    CGGradientRef myGradient = CGGradientCreateWithColorComponents

    (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));

    // Allocate bitmap context

    CGContextRef bitmapContext = CGBitmapContextCreate(NULL, 320, TITLE_CONTROL_HEIGHT, 8, 4 * 320, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst);

    // Draw Gradient Here

    /*

     创建好线性渐变后,我们将使用CGContextDrawLinearGradient过程在图形上下文中绘制,此过程需要五个参数:

     Graphics context 指定用于绘制线性渐变的图形上下文。

     Axial gradient 我们使用CGGradientCreateWithColorComponents函数创建的线性渐变对象的句柄

     start point 图形上下文中的一个CGPoint类型的点,表示渐变的起点。

     End Point表示渐变的终点。 

     Gradient drawing options 当你的起点或者终点不在图形上下文的边缘内时,指定该如何处理。你可以使用你的开始或结束颜色来填充渐变以外的空间。此参数为以下值之一:KCGGradientDrawsAfterEndLocation扩展整个渐变到渐变的终点之后的所有点 KCGGradientDrawsBeforeStartLocation扩展整个渐变到渐变的起点之前的所有点。0不扩展该渐变。

     */

    CGContextDrawLinearGradient(bitmapContext, myGradient, CGPointMake(160.0f, 0.0f),CGPointMake(160.0f, TITLE_CONTROL_HEIGHT),  kCGGradientDrawsBeforeStartLocation);

    // Create a CGImage from context

    CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);

    // Create a UIImage from CGImage

    UIImage *uiImage = [UIImage imageWithCGImage:cgImage];

    // Release the CGImage

    CGImageRelease(cgImage);

    // Release the bitmap context

    CGContextRelease(bitmapContext);

    // Create the patterned UIColor and set as background color

    [titleScrollViewsetBackgroundColor:[UIColorcolorWithPatternImage:uiImage]];
目录
相关文章
|
1月前
|
XML Java 数据处理
深入了解 XPath
【8月更文挑战第22天】
38 0
|
2月前
|
存储 Java 数据库
JPA中@ElementCollection使用
JPA中@ElementCollection使用
37 0
|
3月前
PAT 1001 和 1002 A+B问题
PAT 1001 和 1002 A+B问题
|
4月前
|
机器学习/深度学习 人工智能 算法
PAI-TorchAcc
AI加速引擎PAI-TorchAcc
51 5
3.3 Path
3.3 Path
72 0
|
开发框架 移动开发 安全
mPaaS
mPaaS是阿里云提供的一款移动应用开发平台,支持开发iOS和Android平台的原生应用程序和H5应用程序。mPaaS提供了丰富的移动应用开发服务和工具,包括移动应用开发框架、云端API、移动支付、推送服务、移动安全等,可以帮助开发者快速构建高质量的移动应用程序。
715 0
|
XML 数据格式
|
XML Java 数据库连接
parameterType是必须写的吗?
xml中没有配置parameterType,但是这是正确的,因为mybatis能自动识别,但返回值类型不能不写,因为mybatis需要将获得结果封装到相应的类中,查询的字段与类的属性需要一致。
353 0
parameterType是必须写的吗?
|
Web App开发
XPathHelper使用
XPathHelper使用
143 0
OPA 18 - iTeardownMyAppFrame
Created by Wang, Jerry, last modified on Nov 08, 2015
OPA 18 - iTeardownMyAppFrame