1 @interfaceViewcontroller ()2-(ibaction) Custombtnclick;3 4 @end5 6 @implementationViewcontroller7 8- (void) Viewdidload {9 [Super Viewdidload];Ten //additional setup after loading the view, typically from a nib. One AUIButton *btn =[UIButton Buttonwithtype:uibuttontypecustom]; - - //1. Setting the title the //Btn.titleLabel.text = @ "I am the button";//Please don't write like this . - //In general, the contents of the button settings are setxxx -[BTN Settitle:@"I'm the button ."Forstate:uicontrolstatenormal]; -[BTN Settitle:@"Brother is highlighted"forstate:uicontrolstatehighlighted]; + - //2. Set the title color + //Btn.backgroundcolor = [Uicolor redcolor]; A [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; at - //3. Settings icon -[Btn setimage:[uiimage imagenamed:@"Common_icon_check"] forstate:uicontrolstatenormal]; - - //4. Set the background image -[Btn setbackgroundimage:[uiimage imagenamed:@"common_button_big_blue_highlighted"] forstate:uicontrolstatenormal]; in - //5. Click on the Monitor button to //Target: Who listens to the button + //action: The method to be executed after the supervisor hears - //Events : Type of event the //rule: As long as it is inherited from the Uicontrol control, you can use Addtarget to add monitoring * [btn addtarget:self Action: @selector (Custombtnclick) forcontrolevents:uicontroleventtouchupinside]; $ Panax Notoginseng //Uiswitch sw = nil; - //[SW addtarget:<# (Nullable ID) #> action:<# (nonnull SEL) #> forcontrolevents:<# (uicontrolevents) # ;] the + //Uisegmentedcontrol *sc = nil; A //[SC addtarget:<# (Nullable ID) #> action:<# (nonnull SEL) #> forcontrolevents:<# (uicontrolevents) #& gt;] the + //Uitextfield *tf = nil; - //[TF addtarget:<# (nullable ID) #> action:<# (nonnull SEL) #> forcontrolevents:<# (uicontrolevents) # ;] $ $Btn.titleLabel.font = [Uifont systemfontofsize: -]; -Btn.frame = CGRectMake ( -, -, -, -); - [Self.view addsubview:btn]; the } - Wuyi-(ibaction) Custombtnclick { theNSLog (@"%s", __func__); - } Wu @end
button creation and setup