【问题标题】:Align image with top showing a portion of image in Swift 2 iOS 9将图像与顶部对齐,在 Swift 2 iOS 9 中显示部分图像
【发布时间】:2016-03-14 04:39:08
【问题描述】:

我需要对齐UIImageView,使其只显示图像的顶部。 (请看截图,UIImageView 标有红色轮廓)。 假设图像的宽度 = 320 像素和高度 = 300 像素,那么我想显示全宽:320 像素,但对于高度,只有前 100 像素应该显示。

请指导我如何在 iOS 9 / Swift 2.0 上实现相同的目标。

【问题讨论】:

    标签: ios swift uiimageview swift2 ios9.2


    【解决方案1】:

    您可以使用 imageView 上的 contentMode 属性来缩放图像的一部分。您可以选择几种不同的模式,在下面的示例中我使用了UIViewContentMode.top

    let img = UIImage(named: "image")
    imageView.contentMode = .top
    imageView.clipsToBounds = true
    imageView.image = img
    

    【讨论】:

      猜你喜欢
      • 2012-05-03
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多