UIButton边界和背景图象 [英] UIButton border and background image

查看:80
本文介绍了UIButton边界和背景图象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的:指示是否选择UIButton的边框。

What I Want: A border indicating if a UIButton is selected or not.

背景:我有一些UIButton使用透明图像,而不是文本。这些是切换按钮(即可以打开或关闭)。

Background: I've got some UIButtons using transparent images, not text. These are toggle buttons (i.e. can be on or off).

问题:UIButton类给用户没有指示是否选择按钮,除非你改变别的东西关于按钮。因为图像不随状态改变,我需要两个图像,一个正常,一个选择,并设置一个按钮的每个状态。这是烦人。我想我会改变背景图片,但这会删除按钮上漂亮的边框,我只是得到一个矩形的背景图片,yuck。

Problem: The UIButton class gives users no indication of whether a button is selected or not unless you change something else about the button. Since the image doesn't change with the state, I'd need two of every image, one normal, one selected and set one for each state of the button. This is annoying. I thought instead I'd change the background image, but this removes the pretty border on the button, I just get a rectangle of my background image, yuck.

可能的解决方案我不喜欢:

Possible solutions I don't like:

1)创建一个与UIButton边框匹配的背景,并将其用于所选项。我不喜欢这个,因为他们不完全匹配,我挑剔。

1) Create a background that matches the UIButton border and use that for selected. I don't like this because they wont match perfectly and I'm picky.

2)为每个按钮创建两个图像,基本相同,但具有不同的背景。这似乎是不必要的工作,因为这个问题反复出现,我想要一个解决方案为未来。

2) Create two images for each button, essentially identical but with a different background. This seems like unnecessary work, and since this problem is coming up repeatedly, I want a solution for the future as well.

我希望有人得出一个体面的解决方案目前为止。提前感谢。

I hope somebody's figured out a decent solution to this by now. Thanks in advance.

推荐答案

由于UIButton有两个图像层,一个图像和一个背景图片,我想你可以完成你想通过使用只有两个背景图片为所有的按钮。一个图像显示边框,另一个不显示。当控制状态改变时,交换背景。

Since UIButton has two image layers, an image and a background image, I think you could accomplish what you want by using just two background images for all your buttons. One image shows a border and the other does not. Swap the backgrounds out when the control state changed.

这篇关于UIButton边界和背景图象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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