我需要创建一些圆形的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;
}
答案 0 :(得分:0)
你可以做点什么,
panic()
您可以根据需要修改尺寸和来源。这证明了如何实现这一目标。
希望这有帮助!
答案 1 :(得分:0)
喜欢
UILabel *yourItemlabel = [[UILabel alloc]initWithFrame:CGRectMake(yourView.frame.origin.x + 10, yourView.frame.origin.y + yourView.frame.size.height + 10 , yourView.frame.size.width, 30)]; // customize the height
yourItemlabel.text = @"Request funds";
yourItemlabel.textAlignment = NSTextAlignmentCenter;
[sel.view addSubview:yourItemlabel];