UIButton在不同状态(被点击\正常状态\不可用\ ...)标题是可以不同的


按钮的状态

typedefNS_OPTIONS(NSUInteger,UIControlState){UIControlStateNormal=0,UIControlStateHighlighted=1<<0,//usedwhenUIControlisHighlightedissetUIControlStateDisabled=1<<1,UIControlStateSelected=1<<2,//flagusablebyapp(seebelow)UIControlStateFocusedNS_ENUM_AVAILABLE_IOS(9_0)=1<<3,//ApplicableonlywhenthescreensupportsfocusUIControlStateApplication=0x00FF0000,//additionalflagsavailableforapplicationuseUIControlStateReserved=0xFF000000//flagsreservedforinternalframeworkuse};


以下代码获取正常状态下的标题,并赋值给别的变量


UIControlStateNormal为正常状态

-(IBAction)buttonPressed:(UIButton*)sender{NSString*title=[sendertitleForState:UIControlStateNormal];NSString*plainText=[NSStringstringWithFormat:@"%@buttonpressed.",title];_statusLable.text=plainText;}