UISegmentedControl 中的拉伸图像

问题描述:

我正在尝试向 UISegmentedControl 添加图像,但图像总是自动拉伸以填充整个控件(见图).我目前正在通过调用 setImage:forSegmentAtIndex: 来设置图像.如何设置图像以保持其纵横比?这看起来应该是一件容易的事情,但我一直无法弄清楚.

I'm trying to add images to my UISegmentedControl but the image is always automatically stretched to fill the entire control (see picture). I'm currently setting the image by calling setImage:forSegmentAtIndex:. How can set the image so that it maintains its aspect ratio? This seems like it should be an easy thing to do but I haven't been able to figure it out.

使用足够小的@1x 图像,这样它根本不需要缩放,并且纵横比不会弄乱.当然,您的@2x 和@3x 图像可以更大.

Use a @1x image that is small enough so that it does not need to be scaled at all, and the aspect ratio will not get messed up. Your @2x and @3x images can be larger, of course.