標籤:
IOS中自訂導覽列標題:
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(160, 0, 120, 50)]; titleText.backgroundColor = [UIColor clearColor]; titleText.textColor=[UIColor whiteColor]; [titleText setFont:[UIFont systemFontOfSize:17.0]]; [titleText setText:@"XXX"]; self.navigationItem.titleView=titleText; [titleText release];
IOS中自訂導覽列返回按鈕:(放在pushViewController之前)
UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init]; backItem.title=@"後退"; backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0 blue:129/255.0 alpha:1.0]; self.navigationItem.backBarButtonItem = backItem; [backItem release];
IOS中自訂導覽列右邊按鈕:
UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithTitle:@"回到首頁" style:UIBarButtonItemStyleBordered target:self action:@selector(callModalList)]; rightButton.image=[UIImage imageNamed:@"right_button.png"];rightButton.tintColor=[UIColor colorWithRed:74/255.0 green:74/255.0 blue:74/255.0 alpha:1.0];self.navigationItem.rightBarButtonItem = rightButton;[rightButton release];
或者
//設定返回按鈕 UIButton* backButton = [UIButton buttonWithType:UIButtonTypeCustom]; [backButton setBackgroundImage:[UIImage imageNamed:@"btn_public_back"] forState:UIControlStateNormal]; backButton.frame = CGRectMake(0, 0, 35,35); [backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton]; self.navigationItem.leftBarButtonItem = leftBarItem;
IOS 自訂導覽列標題和返回按鈕標題