1 @implementation Viewcontroller2 3- (void) Viewdidload {4 [Super Viewdidload];5 //additional setup after loading the view, typically from a nib.6MYButton *btn =[MYButton Buttonwithtype:uibuttontypecustom];7Btn.backgroundcolor =[Uicolor Redcolor];8[Btn setimage:[uiimage imagenamed:@" $"] forstate:uicontrolstatenormal];9[BTN Settitle:@"Accounting Computerization Teaching"Forstate:uicontrolstatenormal];TenBtn.frame = CGRectMake ( -, -, the, the); One [Self.view addsubview:btn]; A -}
@implementation MYButton-(Instancetype) initWithFrame: (cgrect) frame{if(self =[Super Initwithframe:frame]) {[Self setUp]; } returnSelf ;}-(ID) Initwithcoder: (Nscoder *) adecoder{if(self =[Super Initwithcoder:adecoder]) {[Self setUp]; } returnSelf ;}- (void) setup{[self settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; Self.titleLabel.font= [Uifont systemfontofsize: -]; Self.titleLabel.textAlignment=Nstextalignmentcenter; }- (void) layoutsubviews{[Super Layoutsubviews]; self.imageview.x= the; Self.imageview.y=5; Self.imageView.contentMode=Uiviewcontentmodescaleaspectfill; Self.titlelabel.y=cgrectgetmaxy (Self.imageView.frame) +5; Self.titlelabel.x=0; Self.titleLabel.width=Self.width; }- (void) Settitle: (NSString *title forstate: (uicontrolstate) state{[Super Settitle:title forstate:state]; [Self sizetofit];}- (void) SetImage: (UIImage *) Image forstate: (uicontrolstate) state{[Super Setimage:image forstate:state]; [Self sizetofit];} @end
Through the custom button can reach the image in the above text in the following as long as adjust the size of the button can easily implement the application picture + application name combination, very convenient to do the application recommended development.
Custom buttons (images in the above text below)