UIButton save selected button, uibutton select button

Source: Internet
Author: User

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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.