iOS -- 內(nèi)邊距 contentInset

  • 內(nèi)邊距 == 切掉設(shè)置區(qū)域,內(nèi)容顯示在未切區(qū)域


    Snip20150927_34.png
  • 以按鈕為例:


    Snip20150927_35.png

    ![Uploading Snip20150927_36_837649.png . . .]


    Snip20150927_37.png
  • contentEdgeInsets

    • 會把UIImageView和UIlabel當(dāng)做一個(gè)整體移動(dòng)
  • titleEdgeInsets/imageEdgeInsets

    • 那么不會影響到另外一個(gè), 也就是只會改變當(dāng)前設(shè)置的這個(gè)控件
案例一
Snip20151025_9.png
  • 代碼實(shí)現(xiàn):
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"024"] forState:UIControlStateNormal];
    [btn setTitle:@"貴賓" forState:UIControlStateNormal];
    btn.frame = CGRectMake(100, 100, 145, 60);
    
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    btn.backgroundColor = [UIColor redColor];
    btn.imageView.backgroundColor = [UIColor greenColor];
    btn.titleLabel.backgroundColor = [UIColor yellowColor];
    
    // 上左下右
    btn.contentEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 0);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
//    btn.imageEdgeInsets = UIEdgeInsetsMake(50, 0, 0, 00);
    
    [self.view addSubview:btn];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容