我使用UILabel作爲導航欄的titleView(我正在製作簡單的應用內網頁瀏覽器)。它工作正常,除了當我呈現一個模式視圖控制器時,titleView從導航欄的中心切換到最左側(在後退按鈕下)。我已經在3.0以上測試過了。下面是相關的代碼:當presentmodalviewcontroller被調用時,爲什麼navigationItem.titleView會左對齊?
- (void)viewDidLoad {
[super viewDidLoad];
// Title view label
CGRect labelFrame = CGRectMake(0.0, 0.0, 120.0, 36.0);
UILabel *label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
label.font = [UIFont boldSystemFontOfSize:14];
label.numberOfLines = 2;
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0, -1.0);
label.lineBreakMode = UILineBreakModeMiddleTruncation;
self.navigationItem.titleView = label;
}
-(void)displayComposerSheet:(NSString*)mailto
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
截圖:
任何想法,爲什麼發生這種情況?謝謝。
In - (void)loadView我已經添加self.label = [[UILabel alloc] initWithFrame:方法self.navigationController.navigationBar.frame]; self.navigationItem.titleView = self.label;然後只改變了自我的文本。標籤 – blyabtroi 2015-12-03 15:28:16