使用swift检查从库中选择的模式uiimage

时间:2018-03-21 05:24:00

标签: ios iphone swift uiimageview uiimage

当我从图库中选择图像时,有" mode1"像这样(图像在风景中)image1和"模式2"像这样(图像是纵向的)image2

图像必须处于模式scaleAspectFit,我想显示一个按钮,仅为uiimages mode1更改内容模式。

为此我想检查所选图像是mode1还是mode2。 我怎么能这样做?

这是我的代码:

let picker = UIImagePickerController()
picker.delegate = self
picker.navigationBar.tintColor = UIColor.white
picker.sourceType = .photoLibrary
self.present(picker, animated: true, completion: nil)

if let original = info["UIImagePickerControllerOriginalImage"] as? UIImage{
    pickerImg_seleccionada = original
}
if let img_seleccionada = pickerImg_seleccionada {
    imageuser.image = img_seleccionada
    //here I want to check if image is like mode1 the button should appear
}
dismiss(animated: true, completion: nil)

提前致谢

1 个答案:

答案 0 :(得分:0)

In this case if imageWidth >= imageHeight then it will be centered on screen so that mode1.

if img_seleccionada.size.width >= img_seleccionada.size.height {
   // mode1
}
else {
   // mode2
}