2012-06-15 5 views
0

사용자 정의 UITableViewCell에서 처음으로 -drawRect를 사용하고 있으며 그려진 텍스트 전체에 1 픽셀 dropShadows를 추가하는 방법과 이미지 (self.image)를 알고 싶습니다. 사전에DrawRect 텍스트 그림자 추가

감사합니다.

- (void) drawRect:(CGRect) rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [[UIColor clearColor] set]; 
    CGContextFillRect(context, rect); 

    if (shouldDrawImage == YES) { 
     CGContextDrawImage(context, CGRectMake(10, 10, 40, 40), self.image.CGImage); 
    } 

    CGContextDrawImage(context, CGRectMake(self.frame.size.width - 16, 0, 16, self.frame.size.height), [UIImage imageNamed:@"right_bar_including_holes"].CGImage);  
    NSString *authorName = [[self.info objectForKey:@"user"] objectForKey:@"full_name"]; 

    [RGB(219, 240, 73) set]; 

    CGSize maximumLabelSize = CGSizeMake(self.frame.size.width - 10 - 55 - 16,9999); 
    CGSize authorsize = [authorName sizeWithFont:[UIFont boldSystemFontOfSize:15] 
            constrainedToSize:maximumLabelSize 
             lineBreakMode:UILineBreakModeWordWrap]; 
    [authorName drawInRect:CGRectMake(60, 10, self.frame.size.width - 60, authorsize.height) withFont:[UIFont boldSystemFontOfSize:15]]; 

    [RGB(249,249,249) set]; 

    NSString *description = [self.info objectForKey:@"description"]; 
    CGSize descriptionSize = [description sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; 

    [description drawInRect:CGRectMake(60, authorsize.height + 15, descriptionSize.width, descriptionSize.height) withFont:[UIFont systemFontOfSize:14]]; 
} 

답변

2

사용 :

CGContextSaveGState(context); 
CGContextSetShadow(context, CGSizeMake(1,1),1); 
//draw text here 
CGContextRestoreGState(context); 

첫번째 파라미터는 문맥되고, 두 번째 파라미터는 오프셋, 세번째 파라미터 흐림이다.

Quartz2d Docs on Shadows

+0

감사합니다. –

+0

부작용으로, 'Shadow Drawing Conventions Context에 따라 달라집니다'에주의하십시오. 오프셋에서 Y 좌표를 뒤집을 필요가 있습니다. – CrimsonDiego