您的位置:首页 > 移动开发 > IOS开发

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: