gpt4 book ai didi

ios - 我也可以像 xcassets 一样在源代码中切片图像资源吗?

转载 作者:行者123 更新时间:2023-11-28 07:33:07 25 4
gpt4 key购买 nike

enter image description here

我想直接在源代码上切片图像,就像在 xcassets 上切片图像的方法一样,如下图所示。我已经在谷歌上找到了方法,但我做不到。如果你知道那是怎么回事,请告诉我吗?谢谢!

最佳答案

当您通过 Storyboard更改图像的切片时,它实际上会将更改应用到与图像对应的 Contents.json 文件。

应用您在附加图像中所做的更改,以下更改将应用​​于文件:

"resizing" : {
"mode" : "9-part",
"center" : {
"mode" : "tile",
"width" : 1,
"height" : 1
},
"cap-insets" : {
"bottom" : 27,
"top" : 26,
"right" : 21,
"left" : 21
}
}

您可以通过使用 UIImage 方法以编程方式应用相同的更改 resizableImage :

Declaration:

func resizableImage(withCapInsets capInsets: UIEdgeInsets, 
resizingMode: UIImage.ResizingMode) -> UIImage

使用示例:

let image = UIImage(named: "example.png")

let insets = UIEdgeInsets(top: 1, left: 2, bottom: 1, right: 2)
let imageWithInsets = image.resizableImage(withCapInsets: insets, resizingMode: .tile)

关于ios - 我也可以像 xcassets 一样在源代码中切片图像资源吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54102591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com