原图,为正方形
就是给图片的cornerRadius设置为图片宽度的一半
#define imgViewW 150 UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, imgViewW, imgViewW)]; imgView.image = [UIImage imageNamed:@"head"]; [self.view addSubview:imgView]; //设为圆形 imgView.layer.masksToBounds = YES; imgView.layer.cornerRadius = imgViewW/2;
效果图
时间: 2024-10-06 20:33:35