渐变多边label

1451553161389_.pic.jpg
- (void)injected {
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"测试";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    
    [self.view addSubview:label];
    label.frame = CGRectMake(0, 0, 200, 100);
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:label.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(50, 50)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = label.bounds;
    maskLayer.path = maskPath.CGPath;
    label.layer.mask = maskLayer;

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = label.bounds;
    [label.layer addSublayer:gradientLayer];

    gradientLayer.colors = @[(__bridge id)HEXCOLOR(0xff9d8e).CGColor, (__bridge id)HEXCOLOR(0xfa6b7f).CGColor];

    //set gradient start and end points
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 1);
    
    label.layer.mask = maskLayer;

}

你可能感兴趣的:(渐变多边label)