“ ContentMode”不是“ UIView”的成员类型

时间:2018-09-20 01:23:17

标签: ios swift uiview

我有以下一段代码可很好地用于旧版IOS应用程序,但现在不再适用于xcode 9:

我得到的错误是:

'ContentMode' is not a member type of 'UIView'

代码如下:

import Foundation

struct ImageViewLayout {
    static func frameForImageWithSize(_ image: CGSize, previousFrame: CGRect, inContainerWithSize container: CGSize, usingContentMode contentMode: UIView.ContentMode) -> CGRect {
        let size = sizeForImage(image, previousSize: previousFrame.size, container: container, contentMode: contentMode)
        let position = positionForImage(size, previousPosition: previousFrame.origin, container: container, contentMode: contentMode)

        return CGRect(origin: position, size: size)
    }

1 个答案:

答案 0 :(得分:4)

枚举类型名称UIView.ContentMode是Xcode 10中引入的Swift 4.2中的新功能。在此之前(例如,您所说的Xcode 9)是UIViewContentMode