有光泽的标签在iOS中查找

时间:2013-12-13 16:40:57

标签: ios uilabel calayer

我正在研究如何使标签看起来具有圆润的光泽外观,类似于: enter image description here

我知道我可以在app中使用CALayer来处理不同的东西,比如边框和圆角,但我不确定是否有光泽外观。现在我正在使用:

CALayer* l = [myCounterLabel layer];
    CALayer* m = [myhiddenlabel layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:11];
    [l setBorderWidth:2.0];
    [l setBorderColor:[[UIColor blackColor] CGColor]];

这给了我一个看起来像这样的标签(我知道字体和其他一切都不匹配......现在只是寻找有光泽的外观: enter image description here

2 个答案:

答案 0 :(得分:0)

您可以尝试使用背景颜色向原始图层添加另一个子图层以填充后半部分:

CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor; //your color
sublayer.frame = CGRectMake(0, 50, 50, 50); //parent layer (height 100, width 50)
[yourLayer addSublayer:sublayer];

答案 1 :(得分:0)

有几种方法可以做到这一点,但CAGradientLayer可能是你最好的选择。假设您有CAGradientLayer*属性:

    self.gradient = [CAGradientLayer layer];
    self.gradient.frame = CGRectMake(100, 100, 100, 100);
    self.gradient.cornerRadius = 11;
    self.gradient.borderWidth = 2.0;
// Set the colors you want in the gradient
    self.gradient.colors = @[(id)[UIColor grayColor].CGColor, (id)[UIColor grayColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor blackColor].CGColor];
// if you want to control as to the distribution of the gradient you can set the control points for the gradient here (make sure you have as many as you have colors)
    self.gradient.locations = @[@0.0f, @0.5f, @0.5f, @1.0f];