ios - UIImageView如何让图片自适应大小而且居右显示呢?
PHPz
PHPz 2017-04-17 15:27:06
0
1
883

如果我选择了UIViewContentModeScaleAspectFit这个自适应模式。大图图片正好自适应,但是居中显示了。

如果我选择UIViewContentModeRight居右模式。图片居右了。但是如果是大图。会超出容器,因为他没有自适应效果。

这个问题如何解决呢?

PHPz
PHPz

学习是最好的投资!

reply all(1)
刘奇
  1. I don’t know if ContentMode supports OR operation, that is (you need to test this method),
    view.contentMode = UIViewContentModeScaleAspectFit|UIViewContentModeRight;
  2. You can extend the UIImage method and crop the UIImage content starting from the right side,

    + (UIImage *)cropFromRight:(CGSize)size
    {
        // size是 UIImageView的大小
        // 根据宽高比,换算出裁剪区域大小,并执行裁剪然后返回 UIImage
    
    }
    

    Similarly, this method can be extended to center cropping, cropping from top, cropping from bottom, etc.

  3. Settings:
    view.layer.masksToBounds = YES;//内容超出控件将不进行显示
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template