我想畫一個帶有文字的圓圈。無法顯示文字。任何幫助?使用CAShapeLayer填充顏色問題
下圖是參考。預期的行爲。
以下是參考代碼:
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'的角落半徑 – Sujay
您正在標籤頂部添加形狀圖層,而不是其他方式。 – stefandouganhyde