源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

IOS设置按钮为圆角的示例代码

  • 时间:2022-01-20 12:15 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:IOS设置按钮为圆角的示例代码
iOS中很多时候都需要用到指定风格的圆角按钮,以下是[code]UIButton[/code]提供的创建圆角按钮方法 [b]设置按钮的4个角:[/b]      左上:[code]UIRectCornerTopLeft[/code]      左下:[code]UIRectCornerBottomLeft[/code]      右上:[code]UIRectCornerTopRight[/code]      右下:[code]UIRectCornerBottomRight[/code] [b]示例代码:[/b]
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 60, 80, 40)];
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
 
//这里设置的是左上和左下角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = button.bounds;
maskLayer.path = maskPath.CGPath;
button.layer.mask = maskLayer;
[b]效果图[/b] [img]http://files.jb51.net/file_images/article/201609/201696115453694.png?20168611553[/img] [b]总结[/b] IOS设置按钮为圆角的方法到这就结束了,大家都学会了吗?希望这篇文章对大家的开发能有一定的帮助,如果有疑问大家可以留言交流。谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部