<i id='pk3p8'><tr id='pk3p8'><dt id='pk3p8'><q id='pk3p8'><span id='pk3p8'><b id='pk3p8'><form id='pk3p8'><ins id='pk3p8'></ins><ul id='pk3p8'></ul><sub id='pk3p8'></sub></form><legend id='pk3p8'></legend><bdo id='pk3p8'><pre id='pk3p8'><center id='pk3p8'></center></pre></bdo></b><th id='pk3p8'></th></span></q></dt></tr></i><div id='pk3p8'><tfoot id='pk3p8'></tfoot><dl id='pk3p8'><fieldset id='pk3p8'></fieldset></dl></div>
    <legend id='pk3p8'><style id='pk3p8'><dir id='pk3p8'><q id='pk3p8'></q></dir></style></legend>

      <bdo id='pk3p8'></bdo><ul id='pk3p8'></ul>

    <small id='pk3p8'></small><noframes id='pk3p8'>

      <tfoot id='pk3p8'></tfoot>

        将 UIImage 放入 UIButton 的简单方法

        时间:2023-07-07
          <tbody id='15BWP'></tbody>

              <small id='15BWP'></small><noframes id='15BWP'>

            1. <tfoot id='15BWP'></tfoot><legend id='15BWP'><style id='15BWP'><dir id='15BWP'><q id='15BWP'></q></dir></style></legend>

                <bdo id='15BWP'></bdo><ul id='15BWP'></ul>

                • <i id='15BWP'><tr id='15BWP'><dt id='15BWP'><q id='15BWP'><span id='15BWP'><b id='15BWP'><form id='15BWP'><ins id='15BWP'></ins><ul id='15BWP'></ul><sub id='15BWP'></sub></form><legend id='15BWP'></legend><bdo id='15BWP'><pre id='15BWP'><center id='15BWP'></center></pre></bdo></b><th id='15BWP'></th></span></q></dt></tr></i><div id='15BWP'><tfoot id='15BWP'></tfoot><dl id='15BWP'><fieldset id='15BWP'></fieldset></dl></div>
                  本文介绍了将 UIImage 放入 UIButton 的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的 iPhone 应用中有一个 UIButton.我将其大小设置为 100x100.

                  I have a UIButton in my iPhone app. I set its size to 100x100.

                  我希望在按钮中显示一个 400x200 的图像.

                  I have an image that is 400x200 that I wish to display in the button.

                  按钮仍然需要保持在 100x100...我希望图像缩小以适应...但是保持正确的纵横比.

                  The button STILL needs to stay at 100x100... and I want the image to downsize to fit... but keep the correct aspect ratio.

                  我认为这就是Aspect Fit"的用途.

                  I thought that's what "Aspect Fit" was used for.

                  我是否将我的图像包含在 setImage 或 setBackgroundImage 中?

                  Do I include my image with setImage, or setBackgroundImage?

                  我是否为按钮设置 AspectFit?还是图像?还是背景图片?

                  Do I set AspectFit for the button? or the image? or the background image?

                  (我需要较小的图像增大尺寸.而较大的图像应该减小尺寸.始终将按钮保持在 100x100.)

                  (I need the smaller images to INCREASE in size. While larger images should DESCREASE in size. Always keeping the button at 100x100.)

                  我已经尝试了上述所有方法的无数组合......但我似乎无法得到一切都在同一时间工作:

                  I've tried countless combinations of all of the above... and I just can't seem to get everything to work at the same time:

                  • 不要将按钮的大小更改为 100x100.
                  • 不要破坏图片的纵横比.
                  • 始终增加小图片以适应按钮.
                  • 始终缩小大图像以适应按钮.
                  • 切勿剪裁任何图像边缘.
                  • 永远不需要将 UIButtons 放在所有 UIimages 上"的技巧.
                  • 不要要求每个人都升级到 v4.2.1 只是为了使用新的框架方法.

                  我看到这么多应用程序,有这么多功能齐全的图像按钮......我简直不敢相信我无法弄清楚这个非常简单、非常常见的事情.

                  I see so many apps, with so many fully-working image-buttons... that I can't believe I can't figure out this very simple, very common thing.

                  呃.

                  推荐答案

                  UIButton 坏了.这是简短的答案.UIImageView 的 image 和 backgroundImage 属性不遵守 UIViewContentMode 设置.它们是只读属性,虽然这些 UIImageView 的 UIImage 内容可以通过 setImage:setBackgroundImage: 方法设置,但内容模式不行.

                  UIButton is broken. That's the short answer. The UIImageViews in its image and backgroundImage properties don't respect UIViewContentMode settings. They're read-only properties, and while the UIImage contents of those UIImageViews can be set through setImage: and setBackgroundImage: methods, the content mode can't be.

                  解决方案是在你的包中提供适当大小的图像,或者放下 UIImageView,按照你想要的方式配置它,然后在它上面放置一个清晰的自定义"UIButton.我保证,这就是你见过的所有花哨的专业应用程序所使用的技巧.我们都必须这样做.

                  The solution is either to provide properly-sized images in your bundle to begin with, or to put a UIImageView down, configure it the way you want it, and then put a clear "custom" UIButton over top of it. That's the hack all those fancy professional apps you've seen have used, I promise. We're all having to do it.

                  这篇关于将 UIImage 放入 UIButton 的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:故事板在按钮内的图像下方定位文本 下一篇:按住自定义 UIButton 时更改深灰色突出显示的颜色?

                  相关文章

                  <legend id='IrO0k'><style id='IrO0k'><dir id='IrO0k'><q id='IrO0k'></q></dir></style></legend>

                  <small id='IrO0k'></small><noframes id='IrO0k'>

                    <bdo id='IrO0k'></bdo><ul id='IrO0k'></ul>

                  1. <i id='IrO0k'><tr id='IrO0k'><dt id='IrO0k'><q id='IrO0k'><span id='IrO0k'><b id='IrO0k'><form id='IrO0k'><ins id='IrO0k'></ins><ul id='IrO0k'></ul><sub id='IrO0k'></sub></form><legend id='IrO0k'></legend><bdo id='IrO0k'><pre id='IrO0k'><center id='IrO0k'></center></pre></bdo></b><th id='IrO0k'></th></span></q></dt></tr></i><div id='IrO0k'><tfoot id='IrO0k'></tfoot><dl id='IrO0k'><fieldset id='IrO0k'></fieldset></dl></div>
                      <tfoot id='IrO0k'></tfoot>