【发布时间】:2016-07-27 06:52:00
【问题描述】:
我需要创建一些圆形 UIView 并在其下方显示文本。我已经成功创建了圈子。但是有什么方法可以在该圆圈下方添加标签。我需要用文字显示很多圆圈。下面是我的圈子代码,附上我需要创建的屏幕截图。
- (UIView*)createCircleViewWithRadius
{
// circle view
UIView *circle = [[UIView alloc] initWithFrame:CGRectZero];
circle.translatesAutoresizingMaskIntoConstraints = NO;
circle.layer.cornerRadius = 50;
circle.layer.masksToBounds = YES;
// border
circle.layer.borderColor = [UIColor lightGrayColor].CGColor;
circle.layer.borderWidth = 1;
// gradient background color
CAGradientLayer *gradientBg = [CAGradientLayer layer];
gradientBg.frame = circle.frame;
gradientBg.colors = [NSArray arrayWithObjects:
(id)[UIColor clearColor].CGColor,
(id)[UIColor clearColor].CGColor,
nil];
// vertical gradient
gradientBg.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:1.0f],
nil];
// gradient background
CALayer *layer = circle.layer;
layer.masksToBounds = YES;
[layer insertSublayer:gradientBg atIndex:0];
return circle;
}
【问题讨论】:
-
请访问此链接,您的问题的答案已经存在:stackoverflow.com/questions/10051514/…