扫码关注官方订阅号
想设置一个圆形的按钮,不知道为啥没有layer那个属性 另外想请教一点 我以前按钮定位都是用的cgRectMake.如果想只设置位置,或者单独设置宽高应该怎么办呢?
若蒙眷顾 不胜惶恐
业精于勤,荒于嬉;行成于思,毁于随。
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 100, 100); btn.layer.cornerRadius = 50.0;
没法只设置位置。只能先把 frame 存起来。
CGRect frame = button.frame; frame.origin = CGPointMake(x, y); // 设置位置 frame.size.width = 20; // 设置宽度 button.frame = frame;
可以写个 UIView 的 category,每次用的时候 include 进来,能省一些代码。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
没法只设置位置。只能先把 frame 存起来。
可以写个 UIView 的 category,每次用的时候 include 进来,能省一些代码。