iOS 圆形按钮(或图片)
2015-12-03 10:40
666 查看
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(50, 50, 60, 60); btn.backgroundColor = [UIColor redColor]; //半径 btn.layer.cornerRadius = 30; //裁边 btn.layer.masksToBounds = YES; //边框宽度 btn.layer.borderWidth = 3.0; //边框颜色 btn.layer.borderColor = [UIColor yellowColor].CGColor; [self.view addSubview:btn]; //想要实现圆形,需要将layer的cornerRadius大小设置为Button宽高的一半,前提width=height
同样图片也可以裁成圆形的,通过layer
self.headImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]]; self.headImage.frame = CGRectMake(20, 20, 80, 80); self.headImage.layer.masksToBounds = YES; self.headImage.layer.cornerRadius = 40; [self.view addSubview:self.headImage];
如果想实现这种小圆边的图片,
//只需要把layer的半径值写小点就可以了 5或10 自己可以试探性改改,就能达到自己想要得效果了. self.headImage.layer.cornerRadius = 10;
相关文章推荐
- iOS 开发 Pch 文件的正确使用
- [iOS进阶]Baidu Map SDK之批量请求
- ios Crash闪退日志获取和上传至服务器
- iOS TableView经常用得到
- IOS通知机制
- iOS tableView的cell的重用问题
- ios 循环遍历整个CollectionView
- iOS——@synthesize 与@dynamic 的不同
- iOS模拟器实现测试3Dtouch
- iOS 时间格式(时间格式转换)
- 归类说明stackoverflow-ios
- IOS 手势识别
- IOS 手势识别
- iOS 事件处理机制与图像渲染过程
- iOS 代码格式化插件Clang-Format
- 远程控制桌面,手机外网远程桌面连接内网的实现过程,详细图文并茂
- 【iOS学习笔记】block
- 【FAQ】ll命令识别不了,没有颜色,怎么办?(ios)
- IOS-IOS集成第三方SDK包的时候可以适量缩小包的大小(shareSDK为例)
- iOS根据文本长度动态计算label的大小