2009-11-07 2 views

답변

4

와우 ... AAA ... 좋아 ... 나는 더 쉬운 방법이있어 : 기본적으로

#import <QuartzCore/QuartzCore.h> 


..... 

UILabel *label = [[UILabel alloc] initWithFrame: 
     CGRectMake(cell.contentView.frame.size.width - 50, 0, 35, 35)]; 
label.layer.cornerRadius = 5; 
label.backgroundColor = [UIColor blueColor]; //feel free to be creative 
label.clipToBounds = YES; 
label.text = @"7"; //Your text here 

[cell.contentView addSubview: label]; 
[label release]; 

, 당신이 만들고있어를 UILabel의를 사용하여 모서리가 둥근 QuartzCore 프레임 워크 - 그것을 포함하는 것을 잊지 마십시오. 추가 참고 사항 : OS> 3.0에서만 작동합니다.

+0

루비 에르, 당신의 방법 바위! – Jordan

3

사용자 정의보기를 만든 다음 수동으로 타원과 숫자를 그려야합니다. 마지막으로 해당 사용자 정의보기를 셀의 부속보기로 지정하십시오. 다음은 Core Graphics를 사용하는 드로잉 코드입니다. 너무 까다로운 아니다 :

 
    CGRect   bounds = self.bounds; 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    float   radius = bounds.size.height/2.0; 
    NSString  *countString = [NSString stringWithFormat: @"%d", _count];

if (_count < 100) bounds = CGRectMake(5, 0, bounds.size.width - 10, bounds.size.height); 

CGContextClearRect(context, bounds); 

CGContextSetFillColorWithColor(context, _color.CGColor); 
CGContextBeginPath(context); 
CGContextAddArc(context, radius + bounds.origin.x, radius, radius, M_PI/2 , 3 * M_PI/2, NO); 
CGContextAddArc(context, (bounds.size.width + bounds.origin.x) - radius, radius, radius, 3 * M_PI/2, M_PI/2, NO); 
CGContextClosePath(context); 
CGContextFillPath(context); 

[[UIColor whiteColor] set]; 

UIFont     *font = [UIFont boldSystemFontOfSize: 14]; 
CGSize     numberSize = [countString sizeWithFont: font]; 

bounds.origin.x += (bounds.size.width - numberSize.width)/2; 

[countString drawInRect: bounds withFont: font]; 

+0

와우. 굉장해. 벤, 루비 에르 말이 맞아. 그의 길은 더 쉽습니다! ;) – Jordan

+0

아, 그래, cornerRadius는 멋지지만, 그가 지적한대로 3.0 만. 약간 오래된 코드입니다. –

+0

Ben, 나는 (심지어 Jailbreakers조차도) 아이폰 OS v2.2.1 또는 이전 버전에 머무르는 것을 선택한 이유를 생각할 수 없다. 너는 할수 있니? – Jordan