简体   繁体   English

如何调整按钮图像和按钮大小从iphone 6到iphone 6+

[英]How to adjust Button image and Button size from iphone 6 to iphone 6+

newbie here. 新手在这里。

I started with iphone 6 for my app. 我从iphone 6开始为我的应用程序。 Say I have a button with fixed size w: 60 and h: 60 and I have a background image for the button : btnImage@2x.png, btnImage@3x and I dont have btnImage@1x.png ( if needed, can use btnImage.png or btnImage@1x.png ?) The size of the image is : 120x120. 假设我有一个固定大小w:60和h:60的按钮,我有一个按钮的背景图片:btnImage@2x.png,btnImage @ 3x我没有btnImage@1x.png(如果需要,可以使用btnImage .png或btnImage@1x.png?)图片大小为:120x120。

In Design view for iphone6. 在iphone6的设计视图中。 It looks good. 看起来不错。

Problem: 1. When viewing in iphone 6+ ( or iphone 7+) in Design view or storyBoard, The Image for the btn look small inside the button? 问题:1。在设计视图或storyBoard中查看iphone 6+(或iphone 7+)时,btn的图像在按钮内看起来很小? I have btnImage@3x.png ,why it did not scale up with @3x image? 我有btnImage@3x.png,为什么它没有扩展@ 3x图像?

What I must do when change from iphone 6 to iphone 6+? 从iphone 6换到iphone 6+时我必须做些什么?

--UPdate --update

Button has two properties : 1) Image 2) Background 按钮有两个属性:1)图像2)背景
using (1) will not scale up 使用(1)不会放大
using (2) , it will scale. 使用(2),它将扩展。

Which one is the proper one? 哪一个是正确的?

Please help. 请帮忙。 Thanks 谢谢

As much as I know the UIButton background image doesnot get scaled. 据我所知,UIButton背景图像不会缩放。 Unless its bigger than the button size resolution. 除非它大于按钮大小分辨率。

I guess that a more proper way to do this. 我想这是一个更合适的方法。 Is to add a UIImageView behind your button and set the image to it. 是在按钮后面添加UIImageView并将图像设置为它。

Alternativly, try the content alignment: 另外,尝试内容对齐:

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill
button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill

This also can be found on storyboard. 这也可以在故事板上找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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