iOS开发常用代码(更新中)

1、渐变色

//静态添加
{
	CAGradientLayer *viewLayer = [CAGradientLayer layer];
	viewLayer.frame = CGRectMake(0, 0, (kScreenWidth - 60), 3);
	viewLayer.startPoint = CGPointMake(0, 0.5);
	viewLayer.endPoint = CGPointMake(1, 0.5);
	viewLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#5500FD"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#FF01AF"].CGColor];
	viewLayer.locations = @[@(0), @(1.0f)];
	[view.layer addSublayer:viewLayer];
}

//动态添加
- (void)addGradientLayerWithView:(UIView *)view {
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.cornerRadius = 0;
    gradientLayer.frame = view.bounds;
    gradientLayer.colors = @[(__bridge  id)kColor(0xBCF649).CGColor,(__bridge  id)kColor(0x00B58E).CGColor];
    gradientLayer.startPoint = CGPointMake(0.5,0);
    gradientLayer.endPoint = CGPointMake(0.5,1);
    gradientLayer.locations = @[@0,@1];
    [view.layer insertSublayer:gradientLayer atIndex:0];
}

你可能感兴趣的:(ios,objective-c,xcode)