几个 uibuttons 子类

发布于 2024-10-06 08:06:29 字数 274 浏览 1 评论 0原文

我的视图中有几个自定义 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 技术交流群。

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

发布评论

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

评论(1

用心笑 2024-10-13 08:06:29

我建议您不要将 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.

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