假设我从图像选择器中选择了图像,现在我想缩放该图像,并希望在按钮或任何图像视图中设置该缩放图像。
答案 0 :(得分:0)
您是否看过contentMode
的{{1}}属性。
UIImageView
答案 1 :(得分:0)
当您从选择器中选择图像时,它应返回UIImage
类型。只需将其设置为任何UIView子类的图像(按钮也是UIView子类):
[yourUIImageView setImage:UIImageFronUIPicker];
[yourUIButton setBackgroundImage:UIImageFronUIPicker];
依旧......
答案 2 :(得分:0)
在视图控制器中实现UIImagePickerControllerDelegate
并实现下面的委托方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[selectedImageBtn setImage:image forState:UIControlStateNormal];
[[imagePicker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[imagePicker parentViewController] dismissModalViewControllerAnimated:YES];
}