【问题标题】:Change the width of an UIBarButtonItem [duplicate]更改 UIBarButtonItem 的宽度 [重复]
【发布时间】:2012-01-28 10:24:23
【问题描述】:

如何将UIBarButtonItem 的宽度更改为 29 像素?属性宽度不起作用,我不想创建UIButton 并使用initWithCustomView,因为我希望方形背景调整为导航栏颜色。 我正在使用initWithImage 来初始化UIBarButtonItem

这是我的按钮,当前宽度为 37 像素。我想设置为 29px。

【问题讨论】:

  • @MaxMacLeod 提问者特别不想使用 initWithCustomView...

标签: objective-c ios width uibarbuttonitem


【解决方案1】:

您可以通过将图像从界面构建器拖放到条形按钮项并使用以下代码更改自定义视图的宽度来实现:

CGRect frame = self.navigationItem.leftBarButtonItem.customView.frame;
frame.size.width = 141;
self.navigationItem.leftBarButtonItem.customView.frame = frame;

【讨论】:

    【解决方案2】:

    你不能。如果你想要自定义宽度,你需要使用initWithCustomView

    【讨论】:

    • 但是为什么它们在 UIBarButtonItem 类中有属性宽度呢?
    • 只有UIToolbar中的按钮才能使用
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多