Ios-button Properties Edge

Source: Internet
Author: User

Settings for the relative seat of the UIButton content, title, background in the button container in iOS

UIButton *button = [Type of UIButton Buttonwithtype:uibuttontypecustom];//button
Button.frame = CGRectMake (100,90, n); frame of//button
Button.backgroundcolor = [background color of Uicolor Cyancolor];//button
[Button setbackgroundimage:[uiimage imagenamed:@ "Man_64.png"] forstate:uicontrolstatenormal];
There are three settings for edgeinsets in UIButton: Contentedgeinsets, Titleedgeinsets, imageedgeinsets
[Button Setimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];//add image to button
Button.imageedgeinsets = Uiedgeinsetsmake (5,13,21,button.titlelabel.bounds.size.width);//sets the position of the image on the button (top , left, next bottom, right) Here you can write negative values, write to 5, then image moves 5 pixels above
[Button settitle:@ "Home" forstate:uicontrolstatenormal];//set the button's title
Button.titleLabel.font = [Uifont systemfontofsize:16];//title font size
Button.titleLabel.textAlignment = nstextalignmentcenter;//Sets the font center of the title
[Button Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];//set title in normal case white font
[Button Settitlecolor:[uicolor Graycolor] forstate:uicontrolstatehighlighted];//set title Gray font when button is selected
Button.titleedgeinsets = Uiedgeinsetsmake (-button.titlelabel.bounds.size.width-50, 0, 0);// Set the title position on the button (top, left, bottom bottom, right)
[Button Setcontentedgeinsets:uiedgeinsetsmake (70, 0, 0, 0)];//
Button.contenthorizontalalignment = uicontrolcontenthorizontalalignmentcenter;//The contents of the button are centered horizontally ... Setting content is changed with title and image

[Button addtarget:self action: @selector (TAP) forcontrolevents:uicontroleventtouchupinside];
[Self.view Addsubview:button];

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.