简体   繁体   中英

How do I manually use the @2x or @3x image from my Assets.xcassets file in Swift?

I am projecting my app's screen onto another screen and noticed the images in my app's buttons look slightly blurry on the external screen. I would like to use the same image except manually use its @2x or @3x image size when I know my screen is projecting.

I have searched around and not found a great answer, can this be done programmatically in Swift?

Make a UITraitCollection whose displayScale is 2 or 3, as desired.

Now use that trait collection, or a combination of the current trait collection with that trait collection, to fetch that variety of your image from the asset collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM