self.rating.text=@"4.5";
self.rating.adjustsFontSizeToFitWidth=YES;
self.rating.textColor = [UIColor blackColor];
self.rating.font = [UIFont fontWithName:@"Helvetica-Bold" size:8.0];
self.rating.layer.borderColor = [UIColor colorWithRed:.2 green:1 blue:0 alpha:1].CGColor;
self.rating.layer.borderWidth = 2.0f;
self.rating.textAlignment=NSTextAlignmentCenter;
self.rating.clipsToBounds=YES;
self.rating.layer.masksToBounds=YES;
当我这样做时,我得到以下o / p
但是我需要将标签边框填充90%,假设最大等级为5并且保持红色
答案 0 :(得分:0)
There are lots of ways to do it, but one is to just draw two bezier paths, one for each side:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
UIBezierPath *blueHalf = [UIBezierPath bezierPath];
[blueHalf addArcWithCenter:CGPointMake(100, 100) radius:90.0 startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:YES];
[blueHalf setLineWidth:4.0];
[blueHalf stroke];
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
UIBezierPath *redHalf = [UIBezierPath bezierPath];
[redHalf addArcWithCenter:CGPointMake(100.0, 100.0) radius:90.0 startAngle:M_PI_2 endAngle:3.0 * M_PI_2 clockwise:YES];
[redHalf setLineWidth:4.0];
[redHalf stroke];
}