Actually, there is nothing to remember about this. The initialization button sets the selected image and the selected image for the button respectively. Add a method to the button. It is OK to implement three sentences in the method. Let’s look at the code directly:
First declare a button in .m
@property (nonatomic, strong) UIButton *selecBtn;
//Initialize buttonUIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; //Set pictures for buttons[button setBackgroundImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal]; [button setBackgroundImage:[UIImage imageNamed:SeleimageArray[i]] forState:UIControlStateDisabled]; //Add method[button addTarget:self action:@selector(changeDataButton:) forControlEvents:UIControlEventTouchDown];
Then in the method as follows:
- (IBAction)btnClick:(UIButton *)btn { = YES; = NO; = btn; }
The above is the iOS button click-to-click and selected switching function introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!