码迷,mamicode.com
首页 > 移动开发 > 详细

IOS uibutton修改圆角和边框

时间:2015-06-17 15:06:05      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

UIButton *testButton = [UIButton buttonWithType:UIButtonTypeSystem];

    [testButton setFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 100, 100)];

    [testButton setTitle:@"获取屏幕尺寸" forState:UIControlStateNormal];


    [testButton.layer setMasksToBounds:YES];//设置按钮的圆角半径不会被遮挡

    [testButton.layer setCornerRadius:10];

    [testButton.layer setBorderWidth:2];//设置边界的宽度

    

    //设置按钮的边界颜色

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    CGColorRef color = CGColorCreate(colorSpaceRef, (CGFloat[]){1,0,0,1});

    [testButton.layer setBorderColor:color];

    
    [testButton addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:testButton];

效果:

技术分享

IOS uibutton修改圆角和边框

标签:

原文地址:http://www.cnblogs.com/xiguain/p/4583094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!