我在我的 UINavigation
栏中放置了一个自定义的 UILabel
,如下所示:
UILabel *navTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
navTitle.backgroundColor = [UIColor clearColor];
navTitle.text = @"TEST";
navTitle.font = [UIFont fontWithName:@"GothamNarrowBook-Regular" size:28];
navTitle.textColor = [UIColor whiteColor];
navTitle.textAlignment = UITextAlignmentCenter;
self.navigationItem.titleView = navTitle;
但是当它出现在模拟器上时,它对齐得太高了:
我没有成功调整框架。有什么想法吗?
最佳答案
您可以将标签放在另一个 View 中,并将另一个作为标题 View 插入。这将允许某种灵 active 。
您也可以尝试调整框架的位置:
UILabel *navTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, >>>10<<<, 200, 44)];
但请记住,NavigationBar 在横向模式下具有不同的高度,因此您必须相应地使用 autoresizingMask。
关于iphone - 如何修复 UINavigationBar 中的 UILabel 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8403972/