iOS -- 内边距 contentInset

  • 内边距 == 切掉设置区域,内容显示在未切区域


    Snip20150927_34.png
  • 以按钮为例:


    iOS -- 内边距 contentInset_第1张图片
    Snip20150927_35.png

    ![Uploading Snip20150927_36_837649.png . . .]


    iOS -- 内边距 contentInset_第2张图片
    Snip20150927_37.png
  • contentEdgeInsets

    • 会把UIImageView和UIlabel当做一个整体移动
  • titleEdgeInsets/imageEdgeInsets

    • 那么不会影响到另外一个, 也就是只会改变当前设置的这个控件
案例一
iOS -- 内边距 contentInset_第3张图片
Snip20151025_9.png
  • 代码实现:
- (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];
}

你可能感兴趣的:(iOS -- 内边距 contentInset)