直到按下另一个按钮

直到按下另一个按钮

本文介绍了按下UIButton(状态选择/突出显示),直到按下另一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图控制器底部有3个按钮,btn1 btn2 btn3,我使用它们而不是标签栏,因为根据我的要求无法完全自定义标签栏。

I have 3 buttons at the bottom of my view controller, btn1 btn2 btn3, I'm using them instead of the tab bar as it is not possible to entirely customize a tab bar as per my requirements.

现在问题是,当按下btn1时,我希望它将其图像更改为灰色矩形,而不是正常状态图像。我使用插座的setimage和uicontrolstate属性在我为按钮btn1Outlet声明的插座中设置了两种状态的图像。

Now the issue is, when btn1 is pressed, I want it to change its image, to a grey rectangle, instead of the normal state image. I have set the images for both states in the outlet I declared for the button, btn1Outlet, using the setimage and uicontrolstate properties of the outlet.

问题是,在按下btn2或btn3之前,我无法保持按钮的选择状态。 btn只要按下它就会改变选定的状态图像,当我离开它时,它会变回正常状态。

The problem is, I can't keep the button selected until say either btn2 or btn3 is pressed. btn one changes to the selected state image only as long as it is pressed, the moment I leave it, it changes back to its normal state.

我如何保持btn1的状态将图像作为所选图像,直到按下任何其他2个按钮?

How can I keep btn1's image as selected image until any of the other 2 buttons are pressed?

推荐答案

您所做的是设置突出显示的图像 状态,这就是为什么当你推它时你可以看到你的形象。

What you did is set an image for the "Highlighted" state, this is why when you push it you can see your image.

你想做的是

1)设置SELECTED状态的图像

1) set the image for the SELECTED state

2)使用助手视图创建视图控制器的属性(只需将按钮拖到标题上)(在故事板上,右上角的第二个方块)

2) create a property for your view controller (just controll drag the button to the header) using the assistant view (while on storyboard, second square on the top right)

3)关于按钮动作类型的方法:

3) on your method for the button's action type:

button.selected = !button.selected;

(显然将按钮替换为您为您的财产命名的任何内容)

(obviously replace button to whatever you named your property to)

这篇关于按下UIButton(状态选择/突出显示),直到按下另一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:24