【问题标题】:UIImage and resizableImageWithCapInsets SwiftUIImage 和 resizableImageWithCapInsets Swift
【发布时间】:2014-10-08 11:00:45
【问题描述】:

我刚接触 Swift 的 Apple。我看过Here的一篇文章

但不知道如何做这样的事情(或者只是不知道如何在 Swift 中使用resizableImageWithCapInsets)。请帮我在 Swift 中使用resizableImageWithCapInsets

【问题讨论】:

    标签: ios swift ios8 uiimage


    【解决方案1】:

    Xcode 6.1 中的通用方式是:

    1. 将 UIImage 创建为变量
    2. 创建插图
    3. 根据原图和插图创建新图,并将其分配给原图

    var myImage = UIImage(named: "navbar.png")!
    let myInsets : UIEdgeInsets = UIEdgeInsetsMake(13, 37, 13, 37)
    myImage = myImage.resizableImageWithCapInsets(myInsets)
    

    【讨论】:

    • 如果您的原始图像很小并且您不想为其命名,请使用以下函数 myImage.resizableImage(withCapInsets: myInsets, resizingMode: .stretch)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多