我正在創建自定義視圖以生成導航欄項目。更改導航欄按鈕文本顏色
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,35)];
UIButton *myBackButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[myBackButton setFrame:CGRectMake(0,0,70,35)];
myBackButton.titleLabel.text = @"Back";
myBackButton.backgroundColor = [UIColor yellowColor];
myBackButton.titleLabel.textAlignment = UITextAlignmentCenter;
myBackButton.titleLabel.textColor = [UIColor blackColor];
[myBackButton setEnabled:YES];
[myBackButton addTarget:self.navigationController action:@selector(moveBack:) forControlEvents:UIControlEventTouchUpInside];
[backButtonView addSubview:myBackButton];
[myBackButton release];
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
self.navigationItem.leftBarButtonItem = backButton;
[backButtonView release];
[backButton release];
CGRect frame = CGRectMake(300, 0, 400, 35);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor yellowColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.text = @"Order booking";
self.navigationItem.titleView = label;
}
return self;
}
有了這個,我有以下的輸出:
我想欄按鈕有相同的背景色導航欄及其在黑色文本。我曾嘗試通過使用UINavigationController代表,但無法獲得成功。 我需要做些什麼改變?請協助。
Nitish
我在哪裏可以下載或查看5.0 documention.may我安裝這個在Xcode 3,請幫助me.where我可以下載WWDC.thanku所有新的示例代碼。我等待烏拉圭回合早日答覆 –
你可以在這裏找到所有的會話(https://developer.apple.com/videos/wwdc/2011/)。會話114被稱爲「自定義UIKit控件的外觀」。您需要使用Apple ID登錄才能看到它。 – ettore
要編碼iOS 5 SDK,您需要Xcode 4.2。目前,會話中有一些示例代碼,但迄今爲止,僅供WWDC與會者使用。我猜新版iOS 5 API的文檔尚未完成,尚未發佈。儘管如此,會話確實會引導您閱讀大量代碼。 –