【问题标题】:Center a button in a navigationBar在导航栏中将按钮居中
【发布时间】:2011-03-08 01:33:54
【问题描述】:

我想在我的导航栏中将一个按钮居中,该按钮当前定义为 rightBarButtonItem :

UIBarButtonItem *audioBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(toggleAudioPlayback:)];
self.navigationItem.rightBarButtonItem = audioBtn;
[audioBtn release];

【问题讨论】:

    标签: iphone objective-c uinavigationbar


    【解决方案1】:

    您可以使用导航项的.titleView 属性 - 但您需要为此创建自己的资产(您将无法使用 UIBarButtonItem)。来自 Apple 的文档:

    ...(titleViews) 可以包含按钮。采用 UIButton 中的 buttonWithType: 方法 类将按钮添加到您的自定义 以导航样式查看 酒吧。自定义标题视图居中 在导航栏上,可能是 调整大小以适应。

    【讨论】:

      猜你喜欢
      • 2019-09-02
      • 2014-03-20
      • 2015-04-01
      • 2015-05-25
      • 2014-10-09
      • 2017-07-17
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      相关资源
      最近更新 更多