Custom buttons (images in the above text below)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.