Change the title position, text color, background color, etc. on the UIButton

Source: Internet
Author: User

UIButton *button = [[UIButton Alloc]initWithFrame:CGRectMake (0,100,200,100)];  Add a Click event[ButtonAddTarget:SelfAction@selector (Pushtosecond)forControlEvents:UIControlEventTouchUpInside];  The background color of the entire button (effect when no background picture is available)Button.backgroundcolor = [Uicolor Greencolor];  Add a background picture[Buttonsetbackgroundimage:[UIImageimagenamed:@"01.png"]Forstate:UIControlStateNormal];  Button title[Buttonsettitle:@"Hello world!"Forstate:UIControlStateNormal];  Horizontal alignment of child controls on a buttonButton.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft;  Vertical alignment of child controls on a buttonButton.contentverticalalignment =Uicontrolcontentverticalalignmenttop;  Offset of the content container to offset the text to the right20 megapixelsButton.contentedgeinsets =Uiedgeinsetsmake (0,20, 0, 0);  //set the background color of the title  Button.titleLabel.backgroundColor = [ span class= "constant" >uicolor purplecolor];   //title color  [button settitlecolor:[uicolor yellowcolor]forstate: uicontrolstatenormal];   Button.imageView.contentMode =  Uiviewcontentmodescaleaspectfit;   [self.view addsubview: Button];  [button release];            

Change the title position, text color, background color, etc. on UIButton

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.