我需要創建一些圓形UIView並在其下方顯示文本。我已經成功創建了圈子。但是有什麼方法可以在該圓圈下方添加標籤。我需要用文字顯示很多圈子。以下是我的代碼圈和附加是我需要創建的屏幕截圖。 如何在UIView子視圖中插入UILabel在iOS中
- (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;
}
請訪問此鏈接,回答你的問題已經存在: http://stackoverflow.com/questions/10051514/how-can-i-insert-a-subview其他子視圖 – Aamir