iphone - iPhone SDK 中导航标题未正确显示

标签 iphone ios xcode uinavigationcontroller

enter image description here

正如您所看到的,导航标题位于两个按钮下方。

两个左/右按钮被添加到导航栏的 subview 。 如何设置导航标题宽度?尽管看起来像...

我的代码如下:

self.navigationItem.titleView.frame=CGRectMake(0, 0, 20, 40);
[[self navigationItem]setTitleView:bigLabel];

最佳答案

如果您的UILable太长,您可以在iphone`中设置导航栏标题,但在ipad中您可以使用相同的逻辑:-

enter image description here

 - (void)viewDidLoad
 {
       [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
       self.navigationItem.leftBarButtonItem = self.editButtonItem;

       UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
       self.navigationItem.rightBarButtonItem = addButton;

       UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
       [label setBackgroundColor:[UIColor clearColor]];
       [label setNumberOfLines:0];
       [label setTextColor:[UIColor whiteColor]];
       [label setTextAlignment:UITextAlignmentCenter];
       [label setFont:[UIFont systemFontOfSize:12]];
       NSString    *str =@"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
       [label setText:str];
       self.navigationItem.titleView = label;

 }

希望它能帮助你..:)

关于iphone - iPhone SDK 中导航标题未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14050345/

相关文章:

iOS 开发者计划证书转移

ios - 以百分比形式为两个 UIView 指定约束

ios - 在 XCode 的一个目标中有两个 GoogleService-Info.plist

iphone - 防止objc block 复制属性

iphone - 如何启用 Core Plot 饼图中部分的触摸选择?

objective-c - 我可以使用 UITabBarController 作为简单的 viewController 切换器吗?

ios - 在表格 View 单元格中添加向下箭头

ios - 应用程序 :didReceiveLocalNotification: not called when app in background

iphone - 来自 XMPP iPhone 的用户配置文件

php - quincykit 无法符号化