我想画一个带有文字的圆圈。无法显示文字。有什么帮助?
下面的图片是参考。对于预期的行为。
以下是参考代码:
UILabel *lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
lblTitle.text = @"Me";
lblTitle.textColor = [UIColor blackColor];
lblTitle.font = [UIFont fontWithName:@"HelveticaNeueLight" size:10.0] ;
lblTitle.textAlignment = NSTextAlignmentCenter;
[view addSubview:lblTitle];
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 40, 40)].CGPath;
circleLayer.fillColor = [UIColor clearColor].CGColor;
circleLayer.fillColor = [UIColor colorWithRed:56.0/255.0 green:212.0/255.0 blue:203.0/255.0 alpha:1.0f].CGColor;
circleLayer.strokeColor = [UIColor blackColor].CGColor;
circleLayer.lineWidth = 1;
[lblTitle.layer addSublayer:circleLayer];
答案 0 :(得分:2)
您可以将UILabel
的cornerRadius设置为@Sujay说:
UILabel *lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(100, 80, 40, 40)];
lblTitle.text = @"Me";
lblTitle.textColor = [UIColor blackColor];
lblTitle.layer.borderWidth = 1;
lblTitle.layer.borderColor = [UIColor blackColor].CGColor;
lblTitle.layer.cornerRadius = lblTitle.bounds.size.height / 2;
lblTitle.layer.masksToBounds = YES;
lblTitle.backgroundColor = [UIColor colorWithRed:56.0/255.0 green:212.0/255.0 blue:203.0/255.0 alpha:1.0f];
lblTitle.font = [UIFont fontWithName:@"HelveticaNeueLight" size:10.0] ;
lblTitle.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:lblTitle];