objective C实现iPhone图标的水晶立体效果的代码

290 阅读1分钟
将代码过程较好的一些代码备份一次,下面的资料是关于objective C实现iPhone图标的水晶立体效果的代码,希望能对码农们有些用。 

- (void)viewDidLoad {
    [super viewDidLoad];
    UIGraphicsBeginImageContext(icon.bounds.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    const CGFloat components[4] = {0.0,0.4,0.0,1.0};
    CGContextSetFillColor(ctx, components);
    CGContextFillRect(ctx, CGRectMake(0, 0, icon.bounds.size.width, icon.bounds.size.height));
    UIGraphicsEndImageContext();
    icon.image = image;
    subLayer.frame = icon.bounds;
    subLayer.contents = (id)[background CGImage];
    maskLayer.frame = icon.bounds;
    maskLayer.contents = (id)[mask CGImage]; 
    [subLayer setMask:maskLayer];
    [[icon layer] addSublayer:subLayer];
    roundCornerLayer.frame = icon.bounds;
    roundCornerLayer.contents = (id)[roundCorner CGImage];
    [[icon layer] setMask:roundCornerLayer];
    [maskLayer release];
    [subLayer release];
    [roundCornerLayer release];
}