如何制作双线边框UIButton? [英] How to make a double line border UIButton?

查看:89
本文介绍了如何制作双线边框UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的按钮有双线边框,就像在图像中一样。

I'd like my buttons to have a double line border, like in the image.

有没有办法以编程方式进行?

Is there a way of doing it programatically?

推荐答案

另一种方法是使用UIImage方法resizableImageWithCapInsets创建一个可伸缩的图像。

Another alternative would be to create a stretchable image using the UIImage method resizableImageWithCapInsets.

你要做的是创建一个将内部折叠到其最小可能尺寸(在此示例中为1个像素)的图像,然后指定边缘的大小。当您以这种方式创建UIImage时,它会将中间扩展为任何所需的大小。这会给你双边框。然后,您可以安装其中一个可伸缩图像作为按钮设置的背景图像,以便在两个维度上调整大小。

What you do is to create an image that has the inside collapsed down to it's smallest possible size (1 pixel in this example) and then specify the sizes of the edges. When you create a UIImage that way it expands the middle to any desired size. This would give you your double border. You'd then install one of these stretchable images as the background image of your button set to resize in both dimensions.

编辑:请记住创建一个3倍大小的图像,然后将其缩小到2倍和1倍大小,因此它在所有不同设备上看起来都很清晰。 (我们仍然需要支持iPad 2,这是非视网膜。如果你只是iPhone,你可以跳过1x,只需保存@ 2x和@ 3x分辨率。)

Remember to create your image a 3x size, then scale it down to 2x and 1x size, so it looks sharp on all the different devices. (We still have to support the iPad 2, which is non-retina. If you're iPhone only you can skip the 1x and just save @2x and @3x resolutions.)

这篇关于如何制作双线边框UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆