关闭

渐变

205人阅读 评论(0) 收藏 举报
分类:

#import "MyView.h"


#define RGBCOLOR(r,g,b,a) [UIColor colorWithRed:(r)/0.0f green:(g)/0.0f blue:(b)/0.0f alpha:a]


@implementation MyView


// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBFillColor(context, 255, 255, 255, 1);

    CGContextFillRect(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));

    

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGFloat alphaGradientLocations[] = {0, 1.0};

    NSArray* alphaGridentColors = @[(id)RGBCOLOR(0, 0, 0, 0).CGColor,

                                    (id)RGBCOLOR(0, 0, 0, 1).CGColor];

    CGGradientRef alphaGradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)alphaGridentColors, alphaGradientLocations);

    CGContextDrawLinearGradient(context, alphaGradient, CGPointZero, CGPointMake(0, self.frame.size.height), 0);

    CGGradientRelease(alphaGradient);

    CGColorSpaceRelease(colorSpace);

}


@end

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:59870次
    • 积分:1948
    • 等级:
    • 排名:千里之外
    • 原创:122篇
    • 转载:101篇
    • 译文:0篇
    • 评论:12条
    最新评论