How to adjust the text position in uibutton

Source: Internet
Author: User
An example of how to adjust the text position in UIButton is as follows:
CGRect btnRect = CGRectMake (360 * 0.5f, 352 * 0.5f, 107, 49); m_iknowBtn = [[UIButton alloc] initWithFrame: btnRect]; [m_iknowBtn setTitle: break (@ "", nil) forState: UIControlStateNormal]; [m_iknowBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; break = [UIFont systemFontOfSize: 18]; response = YES; response = 5; [m_iknowBtn setTitleEdgeInsets: UIEdgeInsetsMake (0, 10, 18, 0)]; [m_iknowBtn setBackgroundImage: [UIImage imageNamed: @ "response"] forState: UIControlStateNormal]; [m_iknowBtn addTarget: self action: @ selector (closeLayer) forControlEvents: UIControlEventTouchUpInside];


The key lies in:

[M_iknowBtn
SetTitleEdgeInsets: UIEdgeInsetsMake (0, 10,
18, 0)];


Where

UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake (CGFloat top,
CGFloat left, CGFloat bottom,
CGFloat right ){

UIEdgeInsets insets = {top, left, bottom, right };

Return insets;

}

Indicates

This indicates that the title is shifted to the right by 10 pixels and 18 pixels to the top.

If the top of the first parameter is positive, it indicates a down offset. If the left of the second parameter is positive, it indicates a remote to the right. If the bottom parameter is positive, it indicates an up offset. If the right parameter is positive, it indicates a left offset.

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.