typedefNS_OPTIONS(NSUInteger,UIControlState){UIControlStateNormal=0,UIControlStateHighlighted=1<<0,// used when UIControl isHighlighted is setUIControlStateDisabled=1<<1,UIControlStateSelected=1<<2,// flag usable by app (see below)UIControlStateApplication=0x00FF0000,// additional flags available for application useUIControlStateReserved=0xFF000000// flags reserved for internal framework use};
-(void)viewDidLoad{[superviewDidLoad];// Do any additional setup after loading the view, typically from a nib.self.view.backgroundColor=[UIColorwhiteColor];CGPointcenter=CGPointMake(CGRectGetWidth(self.view.frame)/2,60.f);UIButton*btn0=[selfgetButton];btn0.center=center;center.y+=60.f;UIButton*btn1=[selfgetButton];btn1.center=center;btn1.highlighted=YES;btn1.enabled=YES;center.y+=60.f;UIButton*btn2=[selfgetButton];btn2.center=center;btn2.selected=YES;center.y+=60.f;UIButton*btn3=[selfgetButton];btn3.center=center;btn3.enabled=NO;center.y+=60.f;UIButton*btn4=[selfgetButton];btn4.center=center;btn4.selected=YES;btn4.enabled=NO;center.y+=60.f;UIButton*btn5=[selfgetButton];btn5.center=center;btn5.highlighted=YES;btn5.enabled=NO;center.y+=60.f;UIButton*btn6=[selfgetButton];btn6.center=center;btn6.highlighted=YES;btn6.selected=YES;btn6.enabled=NO;center.y+=60.f;UIButton*btn7=[selfgetButton];btn7.center=center;btn7.highlighted=YES;btn7.selected=YES;btn7.enabled=YES;[self.viewaddSubview:btn0];[self.viewaddSubview:btn1];[self.viewaddSubview:btn2];[self.viewaddSubview:btn3];[self.viewaddSubview:btn4];[self.viewaddSubview:btn5];[self.viewaddSubview:btn6];[self.viewaddSubview:btn7];}-(UIButton*)getButton{UIButton*btn=[UIButtonbuttonWithType:UIButtonTypeCustom];[btnsetTitleColor:[UIColorblackColor]forState:UIControlStateNormal];[btnsetTitle:@"Normal"forState:UIControlStateNormal];[btnsetTitle:@"Selected"forState:UIControlStateSelected];[btnsetTitle:@"Highlighted"forState:UIControlStateHighlighted];[btnsetTitle:@"Highlighted & Disabled"forState:UIControlStateHighlighted|UIControlStateDisabled];[btnsetTitle:@"Disabled"forState:UIControlStateDisabled];[btnsetTitle:@"Selected & Disabled"forState:UIControlStateSelected|UIControlStateDisabled];[btnsetTitle:@"Selected & Highlighted & Disabled"forState:UIControlStateSelected|UIControlStateHighlighted|UIControlStateDisabled];[btnsetTitle:@"Selected & Highlighted"forState:UIControlStateSelected|UIControlStateHighlighted];btn.bounds=CGRectMake(0,0,240,30);returnbtn;}