【发布时间】:2015-06-04 11:12:53
【问题描述】:
我想画一个圆圈,里面有文字。无法显示文字。有什么帮助吗?
下图是参考。预期行为。
以下是参考代码:
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];
【问题讨论】:
-
你也可以设置
UILabel的cornerRadius试试 -
您是在标签顶部添加形状图层,而不是相反。
标签: ios objective-c iphone cashapelayer