iPhone - 让小图像填充自定义的较大按钮
我有一个 UIButton,我想在其中插入一个可以拉伸到按钮大小的图像。按钮属性允许它“向下”拉伸包含的图像以适应按钮大小,但我想做相反的事情:问题是我的图像很小,如果按钮比图像大,我希望它变大。
我该怎么做?
I have a UIButton in which I want to insert an image that would stretch to the button size. The button property allow it to stretch "down" the included image to fit the button size, but I want to do the opposite : the thing is that my image is small, and I want it to grow if the button is bigger than the image.
How may I do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将图像设置为按钮的背景图像。
Set the image as the background image of the button.
您可以使用属性值 Aspect Fit 或与之相关的其他值。
you can use property value Aspect Fit or something related to it.
我遇到了同样的问题,经过搜索后我发现了一个很好的线程。
如何缩放 UIButton 的 imageView?
我会建议您设置按钮的背景图像这将解决您的问题。
如果您以编程方式调整图像大小,请小心,调整大小将需要一些时间。如果您有多个图像,并且要以编程方式调整大小,请在不同的后台线程上执行此操作,这将保护您的主线程,并且 GUI 不会挂起并在主线程上设置调整大小的图像。
I had same problem and after searching i found a good thread.
How do I scale a UIButton's imageView?
I will suggest you to set background image of button which will solve your problem.
And be careful if you are resizing image programatically it will take time to resize. If you have multiple images and you are resizing programatically do it on different background thread which will protect your main thread and GUI will not hang and set resized image on main thread.