欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

IOS繪制背景色漸變的矩形

兩段代碼,首先是使用方法

創(chuàng)新互聯(lián)建站堅(jiān)信:善待客戶,將會(huì)成為終身客戶。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨嚒N覀儚牟缓鲇瞥踉L客戶,我們用心做好本職工作,不忘初心,方得始終。十載網(wǎng)站建設(shè)經(jīng)驗(yàn)創(chuàng)新互聯(lián)建站是成都老牌網(wǎng)站營(yíng)銷服務(wù)商,為您提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、H5場(chǎng)景定制、網(wǎng)站制作、品牌網(wǎng)站設(shè)計(jì)小程序制作服務(wù),給眾多知名企業(yè)提供過(guò)好品質(zhì)的建站服務(wù)。

CGContextRef context = UIGraphicsGetCurrentContext();
NSArray *colors = [NSArray arrayWithObjects:
                       [UIColor colorWithRed:225.0 / 255.0 green:225.0 / 255.0 blue:225.0 / 255.0 alpha:1.0],
                       [UIColor colorWithRed:168.0 / 255.0 green:168.0 / 255.0 blue:168.0 / 255.0 alpha:1.0],
                       nil];
[self _drawGradientColor:context
                        rect:CGRectMake(rX, rY, rW, rH)
                     options:kCGGradientDrawsAfterEndLocation
                      colors:colors];
    CGContextStrokePath(context);// 描線,即繪制形狀
    CGContextFillPath(context);// 填充形狀內(nèi)的顏色

在一段就是繪制背景色漸變的矩形

/**
 * 繪制背景色漸變的矩形,p_colors漸變顏色設(shè)置,集合中存儲(chǔ)UIColor對(duì)象(創(chuàng)建Color時(shí)一定用三原色來(lái)創(chuàng)建)
 **/
- (void)_drawGradientColor:(CGContextRef)p_context
                      rect:(CGRect)p_clipRect
                   options:(CGGradientDrawingOptions)p_options
                    colors:(NSArray *)p_colors {
    CGContextSaveGState(p_context);// 保持住現(xiàn)在的context
    CGContextClipToRect(p_context, p_clipRect);// 截取對(duì)應(yīng)的context
    int colorCount = p_colors.count;
    int numOfComponents = 4;
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    CGFloat colorComponents[colorCount * numOfComponents];
    for (int i = 0; i < colorCount; i++) {
        UIColor *color = p_colors[i];
        CGColorRef temcolorRef = color.CGColor;
        const CGFloat *components = CGColorGetComponents(temcolorRef);
        for (int j = 0; j < numOfComponents; ++j) {
            colorComponents[i * numOfComponents + j] = components[j];
        }
    }
    CGGradientRef gradient =  CGGradientCreateWithColorComponents(rgb, colorComponents, NULL, colorCount);
    CGColorSpaceRelease(rgb);
    CGPoint startPoint = p_clipRect.origin;
    CGPoint endPoint = CGPointMake(CGRectGetMinX(p_clipRect), CGRectGetMaxY(p_clipRect));
    CGContextDrawLinearGradient(p_context, gradient, startPoint, endPoint, p_options);
    CGGradientRelease(gradient);
    CGContextRestoreGState(p_context);// 恢復(fù)到之前的context
}

還有一種實(shí)現(xiàn)方式

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(rX, rY, rW, rH);
gradient.colors = [NSArray arrayWithObjects:
                       (id)[UIColor blackColor].CGColor,
                       (id)[UIColor grayColor].CGColor,
                       (id)[UIColor blackColor].CGColor,
                        nil];
[self.view.layer insertSublayer:gradient atIndex:0];

記得要

#import <QuartzCore/QuartzCore.h>

此文的完成用到了四位老師的文章,在此表示感謝。

http://www.cnblogs.com/pengyingh/articles/2378840.html

http://www.dapps.net/dev/code/ios-dev-cgcontext-tips.html

http://www.cnblogs.com/smileEvday/archive/2012/06/05/UIColor_CIColor_CGColor.html

http://blog.csdn.net/reylen/article/details/8622932

網(wǎng)站標(biāo)題:IOS繪制背景色漸變的矩形
網(wǎng)站網(wǎng)址:http://chinadenli.net/article4/gjdooe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版手機(jī)網(wǎng)站建設(shè)外貿(mào)建站網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)