开发者

How to have a bordered UIBarButton Item with both Image and Text - Like in Mail

开发者 https://www.devze.com 2023-02-26 15:26 出处:网络
In the Mail app on iPhone, when the user taps Edit, the toolbar shows two buttons, Delete and Move. These buttons have both image and text while appearing as bordered.

In the Mail app on iPhone, when the user taps Edit, the toolbar shows two buttons, Delete and Move. These buttons have both image and text while appearing as bordered.

I tried to recreate this effect, but I have not really succeeded. Here's what I've tried:

  • The obvious way of setting the image and text properties. This results in some weird button with the image on top and the text below it.

  • Initialize the UIBarButtonButton with a custom view set to an instance of UIButton (described here). This button can then not be set to be bordered, instead it appears as a flat view (without shadows either).

I could obviously create a button and then add an UIImageView as a s开发者_StackOverflow社区ubview to the toolbar, but then I have to care about device rotation and some other stuff I would like to avoid. Also, I think Apple doesn't do it this way; when you select an email in Mail while in editing mode, the button label is updated with (-number-), which moves the image slightly to the left. It looks like the text and the image belong together.

So I wonder whether anybody did something like this?


Most likely these are UIButtons with stretchable image backgrounds. That's how I would do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号