iphone - 如何修复 UINavigationBar 中的 UILabel 对齐

标签 iphone ios

我在我的 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;

但是当它出现在模拟器上时,它对齐得太高了:

enter image description here

我没有成功调整框架。有什么想法吗?

最佳答案

您可以将标签放在另一个 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/

相关文章:

objective-c - URLCache - iPhone SDK

ios - 子类化后的AVPlayerViewController横向定位

ios - 嵌套的 dispatch_async(dispatch_async 在另一个 dispatch_async 中)

iphone - 在 iOS SDK 中发出请求,循环飞得太快

ios - Swift MapView 无法显示缩略图

ios - 使用自动布局禁用 UIScrollView 中的水平滚动

iphone - 解析具有相同名称但具有不同属性的元素

iphone - Samsung Smart TV 与 iOS 应用程序之间的连接

ios - 应用程式因1.2苹果规范而被拒绝

ios - 在 Swift 中为 UIDatePicker 设置文本颜色