1. 程式人生 > >IOS之設定UIButton的內容[文字|圖片]的內邊距

IOS之設定UIButton的內容[文字|圖片]的內邊距

import "ViewController.h"
@interface ViewController ()
//繫結一個storyBoard中的按鈕
@property (weak, nonatomic) IBOutlet UIButton *btnText;
@end
@implementation ViewController

/**
 內邊距設定按順時針即:top | right | bottom | left ---> 與css中的內外邊距的設定順序一樣
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    //設定按鈕內容[包括文字和圖片]的內邊距
//self.btnText.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0); //設定按鈕內容[包括文字]的內邊距 self.btnText.titleEdgeInsets = UIEdgeInsetsMake(100, 50, 50, 50); //設定按鈕內容圖片的內邊距 self.btnText.imageEdgeInsets = UIEdgeInsetsMake(100, 100, 100, 100); } @end