gpt4 book ai didi

ios - 如何在 ios 中使用 "css sprites"?

转载 作者:行者123 更新时间:2023-11-29 02:12:19 25 4
gpt4 key购买 nike

我有一个包含多个图标的图像,并且我有我想要显示的图标的位置和大小。

问题是,我怎样才能在 UIImageView 中只显示图像的一部分,这样我才能只显示我想要显示的图标?

是否可以在 1x、2x 和 3x 中正确显示图标,即使图像有点像素化?

最佳答案

您可以裁剪图像的一部分并使用 CGImageCreateWithImageInRect 从中创建一个新的 UIImage:

CGRect cropRect = CGRectMake(x,y,width,height); //Calculate the rect you'd like to show
CGImageRef imageRef = CGImageCreateWithImageInRect(originalImage.CGImage, cropRect);
UIImage* outImage = [UIImage imageWithCGImage:imageRef scale:originalImage.scale orientation:originalImage.imageOrientation];
CGImageRelease(imageRef);

关于ios - 如何在 ios 中使用 "css sprites"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29148412/

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