iOS 15 中的 UIButton 图像行为发生了变化? [英] UIButton image behavior changed in iOS 15?

查看:34
本文介绍了iOS 15 中的 UIButton 图像行为发生了变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码很简单;我有一个 UIButton 的出口,button,我正在代码中设置它的图像:

My code is very simple; I have an outlet to a UIButton, button, and I am setting its image in code:

    let jack = UIImage(named:"jack.png")
    self.button.setImage(jack, for:.normal)

问题是它的行为不像我预期的那样.我希望按钮图像的大小可以缩小到按钮大小,并且我希望它是一个 template 图像(使用继承的色调着色).相反,我看到的是 original 图像,它是全尺寸的.这是 iOS 15 的变化吗?

The problem is that this is not behaving as I expect. I expect the button image to be sized down to the button size, and I expect it to be a template image (tinted with the inherited tint color). Instead, I'm seeing the original image and it is full-sized. Is this a change in iOS 15?

似乎是这样,因为如果我将项目的部署目标设置为 iOS 14 并在 iOS 14 模拟器上运行它,我确实会得到我期望的行为.

It seems to be, because if I set my project's deployment target to iOS 14 and run it on an iOS 14 simulator, I do get the behavior that I expect.

推荐答案

这是 iOS 15 的变化吗?

Is this a change in iOS 15?

是和不是.iOS 15 确实发生了变化,但您遇到问题的原因是 Xcode 13 发生了变化.

Yes and no. There is indeed a change in iOS 15, but the reason for the problem you're experiencing is a change in Xcode 13.

iOS 15 的变化在于有一种全新的按钮配置方式.首先为按钮提供四种新的 iOS 15 类型之一:普通、灰色、有色和填充.如果您将按钮设置为具有这些类型中的任何一种,则表示您选择了新行为.

The change in iOS 15 is that there's a whole new way of configuring a button. This starts with giving the button one of four new iOS 15 types: Plain, Gray, Tinted, and Filled. If you set your button to have any of those types, you are opting in to the new behavior.

您看到的问题是,在 Xcode 13 中,当您在情节提要中创建一个按钮时,它确实为该按钮提供了以下类型之一:Plain.所以你在不知不觉中选择了新的分配!

The problem you're seeing is because, in Xcode 13, when you make a button in the storyboard, it does give the button one of those types: Plain. So you have opted into the new dispensation without knowing it!

如果您想要旧的行为,解决方案是将样式弹出菜单(在属性检查器中)从普通更改为默认.现在你有了一个旧式按钮,它会按照你习惯的方式运行.

The solution, if you want the old behavior, is to change the Style pop-up menu (in the Attributes inspector) from Plain to Default. Now you have an old-style button and it will behave in the way you're accustomed to.

(当然,从长远来看,你会想要采用新的分配方式.我只是在解释行为的明显变化.)

(Of course, in the long run, you're going to want to adopt the new dispensation. I'm just explaining the apparent change in behavior.)

这篇关于iOS 15 中的 UIButton 图像行为发生了变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆