iPhone:如何减少 UIBarButtonItemWidth?

发布于 2024-07-23 22:49:11 字数 382 浏览 3 评论 0原文

我创建了一个 UIBarButtonItem,然后将 self.navigationItem.rightBarButtonItem 设置为该项目。

但是,设置 barButtonItem 的 width 属性似乎对按钮的宽度没有任何影响(我正在尝试减小 barButton 的宽度)

如果我对 UIBarButtonItem 使用自定义视图,我可以设置视图的宽度(进而设置 barButton 的宽度)

但是,我想获得标准 UIBarButtonItem 的外观和感觉。

有谁知道如何在不使用自定义视图的情况下减少 UIBarButtonItem 的宽度? (或者,有谁知道如何创建看起来像 UIBarButtonItem 的 UIView 或 UIButton)

I've created a UIBarButtonItem and then set self.navigationItem.rightBarButtonItem to the item.

However, setting the width property of the barButtonItem doesn't seem to have any effect on the width of the button (I'm trying to reduce the width of the barButton)

If I use a custom view for the UIBarButtonItem, I'm able to set the width of the view (and that in turn sets the width of the barButton)

However, I want to get the look and feel of the standard UIBarButtonItem.

Does anyone know how to reduce the width of the UIBarButtonItem without using a custom view ?
(alternately, does anyone know how to create a UIView or UIButton that looks like a UIBarButtonItem)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-07-30 22:49:11

看来苹果真的不想要它(人机界面指南)。 然而,如果您使用自己的视图,则有一个有点静态的解决方案:

只需使用图像即可...使用grab以您想要的宽度从IB复制图像。
然后它们看起来就像 UIBarButtons 一样,

Apple 向您展示了如何根据状态将两个不同的图像(在本例中也是功能)映射到同一个按钮...查看“添加音乐”示例代码:http://developer.apple.com/iphone/library/samplecode/AddMusic/ index.html

这是来自 TechGuru @ http://discussions.apple。 com/thread.jspa?messageID=9822548

Looks like Apple really don't want it (Human Interface Guidelines). However there is a somewhat static solution if you use your own view for it:

Just use images instead... use grab to copy the images from IB at the widths you want.
Then they'll look exactly like the UIBarButtons

Apple shows you how to map two different images (and in this example functions as well) to the same button depending on the state... check out the "Add Music" sample code: http://developer.apple.com/iphone/library/samplecode/AddMusic/index.html

This is from TechGuru @ http://discussions.apple.com/thread.jspa?messageID=9822548

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文