2013-12-13 43 views
0

我在看如何让一个标签似乎有一个圆形光滑的外观,与此类似: enter image description here光泽标签外观iOS中

我知道我可以使用的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

回答

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]; 
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];