我使用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