简体   繁体   中英

How can I scale selected image iPhone sdk?

假设我已经从图像选择器中选择了图像,现在我想缩放该图像,并想要在按钮或任何图像视图中设置该缩放图像。

Did you take a look at the contentMode property of the UIImageView .

typedef enum {
   UIViewContentModeScaleToFill,
   UIViewContentModeScaleAspectFit,
   UIViewContentModeScaleAspectFill,
   UIViewContentModeRedraw,
   UIViewContentModeCenter,
   UIViewContentModeTop,
   UIViewContentModeBottom,
   UIViewContentModeLeft,
   UIViewContentModeRight,
   UIViewContentModeTopLeft,
   UIViewContentModeTopRight,
   UIViewContentModeBottomLeft,
   UIViewContentModeBottomRight,
} UIViewContentMode;

when you picking an image from picker, it should returt UIImage type. just set it as image to any UIView sublass (button are UIView sub class too):

[yourUIImageView setImage:UIImageFronUIPicker];
[yourUIButton setBackgroundImage:UIImageFronUIPicker];

and so on...

Implement a UIImagePickerControllerDelegate in your view controller and implement the delegate methods below

- (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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM