//1. Add a buttonUIButton *nameview=[UIButton Buttonwithtype:uibuttontypecustom]; //Nameview.backgroundcolor=[uicolor Redcolor];[Nameview setbackgroundimage:[uiimage imagenamed:@"BUDDY_HEADER_BG"] Forstate:uicontrolstatenormal]; [Nameview setbackgroundimage:[uiimage imagenamed:@"buddy_header_bg_highlighted"] forstate:uicontrolstatehighlighted]; //set the left arrow image inside the button[Nameview setimage:[uiimage imagenamed:@"Buddy_header_arrow"] Forstate:uicontrolstatenormal]; [Nameview Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; // //set the contents of the button to align left//Nameview.contenthorizontalalignment=uicontrolcontenthorizontalalignmentleft; //set the contents of the button to align leftNameview.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft; //set the inner margin of a buttonNameview.titleedgeinsets=uiedgeinsetsmake (0,Ten,0,0); Nameview.contentedgeinsets=uiedgeinsetsmake (0,Ten,0,0); [Nameview addtarget:self Action: @selector (Nameviewclick) forcontrolevents:uicontroleventtouchupinside]; //Center The content model of the ImageView inside the set buttonNameview.imageview.contentmode=Uiviewcontentmodecenter; //content beyond the border does not need to be croppednameview.imageview.clipstobounds=NO; [Self.contentview Addsubview:nameview]; Self.nameview=Nameview;
IOS UIButton Common Properties