使用Swift调整主屏幕亮度 [英] Adjust the main screen brightness using Swift

查看:358
本文介绍了使用Swift调整主屏幕亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Swift在代码中调整iPhone的主屏幕亮度.

I would like to adjust the iPhone's main screen brightness in code using Swift.

我知道在Objective-C中可以通过以下方式完成:

I know in Objective-C it can be done by:

[[UIScreen mainScreen] setBrightness:0.5];

我该如何在Swift中做到这一点?

How do I do this in Swift?

推荐答案

https: //developer.apple.com/documentation/uikit/uiscreen/1617830-亮度

在文档中,Swift 3+的正确答案是:

From the docs the proper answer for Swift 3+ is:

UIScreen.main.brightness = CGFloat(0.5)

这篇关于使用Swift调整主屏幕亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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