UIButton3

// 内容偏移
- (void)test9 {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 200, 200);
    //    button.backgroundColor = [UIColor redColor];
    button.backgroundColor = [UIColor lightGrayColor];
    [button setBackgroundImage:[UIImage imageNamed:@"屏幕快照 2015-08-23 上午11.13.46"] forState:UIControlStateNormal];
    [button setTitle:@"hello" forState:UIControlStateNormal];
    //    contentEdgeInsets 整体内容偏移
    // imageEdgeInsets image偏移
    // titleEdgeInsets title偏移
    button.contentEdgeInsets = UIEdgeInsetsMake(100, 0, 0, 0);
    //    button.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    
    [self.view addSubview:button];
}
// 关于UIButton的圆角 边框颜色 回调方法
- (void)test8 {
    
    //  当使用custom类型的button的时候,你可以指定按钮的背景色,但是当你运行时
    //    按钮就失去了圆角特性,你看到的仅仅是一个方块。
    //    custombutton没有定义任何属性默认值,我们必须自己去定义他们。这就需要使用到了
    //    core animation layer
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:btn];
    btn.frame = CGRectMake(100, 100,100, 100);
    // layer 图层
    // maskstobounds 告诉layer将位于它之下的layer都遮盖掉
    [btn.layer setMasksToBounds:YES];
    // cornerRadius 圆角半径
    [[btn layer] setCornerRadius:8.0f];
    // borderwidth 设置边框宽度 默认边框颜色为黑色
    [[btn layer] setBorderWidth:1.0f];
    // 设置边框颜色
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorRef = CGColorCreate(colorSpace, (CGFloat[]){1,0,0,1});
    [btn.layer setBorderColor:colorRef];
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值