[IOS] button related

1. Set the text

[btn setTitle: @"search" forState: UIControlStateNormal];

 *Note: using btn.titleLabel.text = @"xxx" doesn't work

 

2. Set the font

btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];

 

3. Set the font color

[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];

 Note: Do not use:

[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor = [UIColor redColor];

 

4. Round button

//Premise: The button should be set to a square
btn.layer.cornerRadius = wireBtn.bounds.size.width/2;
btn.layer.masksToBounds = wireBtn.bounds.size.width/2;

 

 5. Picture button

[deviceImageBtn setImage:[UIImage imageNamed:@"icobarico_4.png"] forState:UIControlStateNormal];

 

6.Button click event parameters:

  1. Set tag: btn.tag = 101;

  2. Use as follows:

-(void)circleBtnClicked:(UIButton*)sender{
    switch (sender.tag) {
        case 101:
            {
                UIStoryboard *wireboard = [UIStoryboard storyboardWithName:@"MyDevice" bundle:nil];
                LoginController *wirevc = [wireboard instantiateViewControllerWithIdentifier:@"my_device_home"];
                [self.navigationController pushViewController:wirevc animated:YES];
            }
            break;
            
        case 2:
            break;
    }
    
}

  

7. Set the button with text and picture:

1.http://www.jianshu.com/p/3052a3b14a4e

2.http://blog.csdn.net/u011462377/article/details/48595485

8. Text wrapping in the button:

_parental_control_btn.titleLabel.textAlignment = NSTextAlignmentCenter;
_parental_control_btn.titleLabel.numberOfLines = 0;

If necessary, you can also add \n to the value of Localizable.strings, and the display effect will be different.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326163480&siteId=291194637