·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> iOS中UIKit——UIButton设置边框

iOS中UIKit——UIButton设置边框

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

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];

   

  实现效果:

    

 


 

我的CSDN博客地址:http://blog.csdn.net/qw963895582/article