简体   繁体   English

如何缩放选定的图像iPhone SDK?

[英]How can I scale selected image iPhone sdk?

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

Did you take a look at the contentMode property of the UIImageView . 您是否看过UIImageViewcontentMode属性。

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. 当您从选择器中选择图像时,应该扭曲UIImage类型。 just set it as image to any UIView sublass (button are UIView sub class too): 只需将其设置为任何UIView子图像的图像即可(按钮也是UIView子类):

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

and so on... 等等...

Implement a UIImagePickerControllerDelegate in your view controller and implement the delegate methods below 在视图控制器中实现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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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