2011-07-06 26 views
0

進出口試圖創建一個UILabel子類,將完成2個獨立的UILabels我已經堆疊在使用以下方法彼此的頂部上的任務:創建行程和陰影影響僅使用1的UILabel子類

背景的UILabel :

- (void)drawTextInRect:(CGRect)rect { 

CGSize shadowOffset = self.shadowOffset; 
//UIColor *textColor = self.textColor; 

CGContextRef c = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(c, 3); 

CGContextSetTextDrawingMode(c, kCGTextStroke); 
self.textColor = [UIColor whiteColor]; 
[super drawTextInRect:rect]; 

self.alpha = .1; 

self.shadowOffset = shadowOffset; 

} 

前景的UILabel:

- (void)drawTextInRect:(CGRect)rect { 

CGSize shadowOffset = self.shadowOffset; 
UIColor *textColor = self.textColor; 

CGContextRef c = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(c, 2); 

CGContextSetTextDrawingMode(c, kCGTextStroke); 
self.textColor = [UIColor blackColor]; 
[super drawTextInRect:rect]; 


CGContextSetTextDrawingMode(c, kCGTextFill); 
self.textColor = textColor; 
self.shadowOffset = CGSizeMake(0, 0); 
[super drawTextInRect:rect]; 

self.alpha = .5; 

self.shadowOffset = shadowOffset; 

} 

有沒有辦法做到這2套影響使用僅1的UILabel子類的?

回答

1

試試這個代碼:

UILabel* label = [[UILabel alloc] init]; 
label.shadowColor = [UIColor grayColor]; 
label.shadowOffset = CGSizeMake(0,1);