2014-05-22 11 views
0
[email protected]"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標籤顯示拉布勒的評價和邊界應部分填充特定的顏色來評價IOS

但我需要的標籤邊框將被填充90 %假設最高評級將在5到其餘的紅

回答

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]; 
} 
+0

我已經創建了一個從的UILabel繼承的類,然後創建了標籤的對象,然後叫setNeedsDisplay方法,但它仍然亙古不變的工作,它不是要求實現drawRect方法在我的標籤類 – satisharyan

+0

這種方式是否定的不工作的默認角落半徑被設置爲默認黑色 – satisharyan