UIButton3

来源:互联网 发布:安润金融 知乎 编辑:程序博客网 时间:2024/06/03 17:29

// 内容偏移- (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];    }


0 0
原创粉丝点击