UIButton save selected button, uibutton select button
// After four hours, the button finally came out. The effect was to save the selected button for data transmission,
// Color button
NSMutableArray * showLabelArray = [NSMutableArrayarrayWithCapacity: 10];
[ShowLabelArrayaddObject: @ "2 string 1"]; // 0
[ShowLabelArrayaddObject: @ "3 string 1"]; // 2
[ShowLabelArrayaddObject: @ "4 string 1"]; // 9
[ShowLabelArrayaddObject: @ "5 string 1"]; // 1
[ShowLabelArrayaddObject: @ "6 string 1"]; // 5
[ShowLabelArrayaddObject: @ "7 string 1"]; // 8
[ShowLabelArrayaddObject: @ "8 string 1"];
// Add color button
UIButton * btn = nil;
For (int I = 0; I <2; I ++ ){
For (int j = 0; j <4; j ++ ){
If (I = 1 & j = 3 ){
Break;
}
Btn = [UIButtonbuttonWithType: UIButtonTypeCustom];
[Btn setTitle: [showLabelArrayobjectAtIndex: I * 4 + j] forState: UIControlStateNormal];
[Btn setTitleColor: [UIColorblackColor] forState: UIControlStateNormal];
Btn. layer. borderColor = [UIColorlightGrayColor]. CGColor;
Btn. layer. borderWidth = 0.7;
Btn. showsTouchWhenHighlighted = YES;
[Btn addTarget: selfaction: @ selector (chooseLottery :) forControlEvents: UIControlEventTouchUpInside];
Btn. frame = CGRectMake (10 + j * 80, 50 + I * 40, 60, 30 );
Btn. tag = 10 + I * 4 + j;
[Button setBackgroundImage: [UIImageimageNamed: @ "leagueBtn"] forState: UIControlStateNormal];
[ChooseBackroundViewaddSubview: btn];
NSLog (@ "btn. tag is % d", btn. tag );
}
}
-(Void) chooseLottery :( UIButton *) sender {
UIButton * button = (UIButton *) sender;
For (int I = 0; I <2; I ++ ){
For (int j = 0; j <4; j ++ ){
If (I = 1 & j = 3 ){
Break;
Button = (UIButton *) [self. viewviewWithTag: I * 4 + j];
}
}
}
If (button. selected = YES)
{
Button. selected =! Button. selected;
[Button setBackgroundImage: [UIImageimageNamed: @ "leagueBtn"] forState: UIControlStateNormal];
NSString * tag1 = [NSStringstringWithFormat: @ "% d", button. tag];
[ArrayremoveObject: tag1];
}
Else if (button. selected = NO)
{
Button. selected =! Button. selected;
[Button setBackgroundImage: [UIImageimageNamed: @ "leagueBtn_selected"] forState: UIControlStateNormal];
NSString * tag1 = [NSStringstringWithFormat: @ "% d", button. tag];
[ArrayaddObject: tag1];
}
For (int I = 0; I <[arraycount]; I ++ ){
NSString * str = [arrayobjectAtIndex: I];
NSLog (@ "tag % @", str corresponding to the Save button array );
}
In iOS development, how does one enable UIImageView to achieve the UIButton click effect, that is, the system's built-in Button click will gradually change color
We recommend that you use a custom UIButton to create a whole picture of two images and text, and use it as a button texture.
How can I dynamically change the title text of UIButton?
You have added a button to the view! But how can I assign values to the above text using code? Use set title: for state: Hard to enable