【发布时间】:2018-01-28 06:20:24
【问题描述】:
我知道这是一个常见问题,但我有能力实施它。我有一个体重和身高相等的图像视图。当我从媒体库中选择图像时,有些图像适合圆形,但有些图像不适合圆形图像视图。
谁能建议我如何将任何类型的图像集设置为圆形图像视图?
因为我想实现用户可以设置他/她的个人资料图像。所以用户插入任何类型的图像或任何分辨率,我需要裁剪该图像但我无法做到这一点.而且我也不喜欢任何第三个图书馆。
这是我的代码:
-(void)btnImgAct //Button Action
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:imagePickerController animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)Info
{
UIImage *pickerImage=[[UIImage alloc]init];
pickerImage=image;
imageDataPicker =[[NSData alloc] init];
imageDataPicker = UIImageJPEGRepresentation(pickerImage, 0.1); //For resize
if([imageDataPicker length]<2097152) //bytes 1048576
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
picker=nil;
[self SubmitImage1:pickerImage];
}
-(void)SubmitImage1:(UIImage *)image
{
EditProfileImage.image=image; //insert image into imageview
//Create circle imageview
EditProfileImage.layer.cornerRadius = EditProfileImage.frame.size.width / 2;
[EditProfileImage setContentMode:UIViewContentModeScaleAspectFit];
EditProfileImage.layer.masksToBounds = YES;
EditProfileImage.layer.borderWidth = 3.0f;
EditProfileImage.layer.borderColor = [UIColor blackColor].CGColor;
}
【问题讨论】:
-
到底是什么问题?是不是你种植不好?在这种情况下,请尝试改用内容模式
UIViewContentModeScaleAspectFill。这将用图像填充你的圆圈。 -
@LGP,当我从库中插入图像时,这是任何图像适合圆形视图但某些图像不适合圆形的任何结果。你也可以建议我如何辞职的形象。我的 imageview 体重和身高是 100.0f。
-
您能否展示一张不合适的图片的外观?
-
嗨@LGP,我已经更新了我的问题。请看上面的图片链接。请提出任何想法,因为我不知道为什么我会显示不需要的问题。
标签: objective-c uiimageview xcode8 ios9