几个 uibuttons 子类
我的视图中有几个自定义 uibuttons。我想创建一个切换按钮,按下该按钮时,它将循环遍历所有 UIButton 并为其启用背景图像。
我所做的是使用图像作为背景,然后使用空白自定义按钮创建其可点击部分。我希望这个切换功能能够显示按钮。
我的计划是为“隐藏”按钮创建一个子类 UIButton。当按下切换按钮时,代码应该将每个按钮的背景图像设置为“reddot.png”。它会保留在屏幕上,直到再次按下切换按钮 - 然后禁用每个子类 uibuttons 背景图像。
最好的方法是什么?
I have several custom uibuttons on my view. I want to create a toggle button which when pressed, it will loop through all the UIButtons and enable a background image for them.
What I have done is to use an image as a background, then created clickable parts of it using blank custom buttons. I want this toggle function to then show the buttons.
My plan is to create a subclassed UIButton for the "hidden" buttons. When the toggle button is pressed, the code should then set the background image for each of these buttons to a "reddot.png". That stays on the screen until the toggle button is pressed again - this then disables each sub classed uibuttons background image.
What's the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您不要将 UIButton 子类化,原因有两个。首先,UIButton 实际上是一个类簇,这使得子类化相当困难。其次,我认为你的情况没有必要。
只需将所有按钮创建为自定义按钮即可。您可以使用
[button setHidden:]
和[button setBackgroundImage:forState:]
等方法自定义其外观。然后,切换按钮可以简单地链接到 IBAction,这会将适当的自定义应用到其他按钮。I would advise you to not subclass UIButton for two reasons. First, UIButton is actually a class-cluster, which makes subclassing rather difficult. Secondly, I don't think it is needed in your case.
Simply create all the buttons as custom buttons. You can customize their appearance using methods like
[button setHidden:]
and[button setBackgroundImage:forState:]
. The toggle button could then simply by linked to an IBAction, which would apply the appropriate customizations to the other buttons.