2011-07-01 44 views
1

我使用PNG製作了一個自定義backBarButtonItem,工作得很好。唯一的問題是如何改變文字顏色。我這樣做,我的導航欄上的方法是這樣的:爲backBarButtonItem製作自定義標題視圖

CGRect frame = CGRectMake(0, 0, 400, 44); 
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease]; 
label.backgroundColor = [UIColor clearColor]; 
label.font = [UIFont boldSystemFontOfSize:20.0]; 
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; 
label.textAlignment = UITextAlignmentCenter; 
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]]; 
self.navigationItem.titleView = label; 
label.text = @"aTitle"; 
+0

做ü想改變PNG的文本顏色? – Aravindhan

回答

1

不使用自動釋放了一套標籤titleview的,之後將它們分配釋放他們

 CGRect frame = CGRectMake(0, 0, 400, 44); 

     UILabel *label = [[UILabel alloc] initWithFrame:frame]; 

     label.backgroundColor = [UIColor clearColor]; 

     label.font = [UIFont boldSystemFontOfSize:20.0]; 

     label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5]; 

     label.textAlignment = UITextAlignmentCenter; 

     label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]]; 

     label.text = @"aTitle"; 

     self.navigationItem.titleView = label; 

     [label release];