简体   繁体   中英

Which content mode to use for scaling an image in an UIButton?

I am developing a project for iOS, using storyboard for setting up the views. If I have a UIViewController with some UIButtons , all of the same size. Lets say 100 points width and 75 points height.

I have a variety of images, of all kinds of shapes, but all falling within this [100 width / 75 height] rectangle. I want the images to keep their original size, shape & quality. So I guess I want to use center and/or aspect fit for content mode. Is this the correct mode? But aspect fit is especially needed, when an image is bigger then the UIButton , right?

What if the image is a fraction bigger then the [100 width / 75 height] rectangle, and I use aspect fit for content mode. This will 'scale down' the image to the size of the UIButton , right? Will the quality of the image decrease then? If yes, can this be a big decrease, or just marginal?

I want the images to keep their original size, shape & quality. So I guess I want to use center and/or aspect fit for content mode. Is this the correct mode?

If you want button to change it's frame according to image then you should get image.size and update the frame of the button.

But aspect fit is especially needed, when an image is bigger then the UIButton, right?

Right!

What if the image is a fraction bigger then the [100 width / 75 height] rectangle, and I use aspect fit for content mode. This will 'scale down' the image to the size of the UIButton, right?

Right!

Will the quality of the image decrease then? If yes, can this be a big decrease, or just marginal?

Quality of image decrease when you scale up a Image. So Scaling down does;t make a big impact on image (if scaled in ratio).

内容模式Aspect Fit始终是将图像放在iOS中任何位置的最佳选择

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