Adjust the relative positions of UIButton images and text, and uibutton Images

Source: Internet
Author: User

Adjust the relative positions of UIButton images and text, and uibutton Images

Generally, If you directly set the image and text of UIButton, the relative positions of the two by default may not be what we want, so you need to adjust them.

The required functions are as follows:

UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)

Top, left, bottom, and right indicate the movement volume in each direction respectively.

Instance description:

UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (50,100,300,300)]; // set the text [button setTitle: @ "test" forState: UIControlStateNormal]; [button setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; button. titleLabel. font = [UIFont systemFontOfSize: 25]; // set the background color of the button to black for differentiation. backgroundColor = [UIColor blackColor]; // set the image [button setImage: [UIImage imageNamed: @ "QQ"] forState: UIControlStateNormal]; [self. view addSubview: button];

:

Adjustment:

// If You Want To adjust the position of the title to the bottom of the image, you can adjust the title downward and move the button. titleEdgeInsets = UIEdgeInsetsMake (125,-150, 0, 0) to the left );

:

Generally, the size of the button is not so large, so you must adjust the position of the title and image at the same time in a limited space.

    button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);    button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.