如何生成圆形的图片
如何生成圆形的图片呢?今天就总结一下:
1、添加Photo.m和Phone.h两个文件
2、添加头文件Photo.h
3、创建圆角UIImageView
self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(124, 40, 72, 72)]; self.headImageView.layer.borderWidth = 2.0;//边宽 self.headImageView.layer.borderColor = [UIColor colorWithWhite:1.0 alpha:0.3].CGColor;//边颜色 self.headImageView.layer.cornerRadius = 36;//切圆角视图,为高的一半 self.headImageView.layer.masksToBounds = YES;//切割多余视图 self.headImageView.image = [UIImage imageNamed:@"add_photo_hav"];//默认图片 [self.view addSubview:self.headImageView];
4、在UIImagePickerViewDelegate的函数中,切圆角图片
1 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 2 UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; 3 image = [Photo scaleImage:image toWidth:100 toHeight:100];//切的图片要比视图大 4 self.headImageView.image = image; 5 [self dismissViewControllerAnimated:YES completion:nil]; 6 }
5、完成