使用 CAShapeLayer 填充颜色问题
Using CAShapeLayer fill color issue
我想用文字 inside.Unable 画一个圆来显示 text.Any 帮助?
下图为参考。对于预期的行为。
以下代码供参考:
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,如@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];
我想用文字 inside.Unable 画一个圆来显示 text.Any 帮助?
下图为参考。对于预期的行为。
以下代码供参考:
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,如@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];