Adjust the main screen brightness using Swift

不羁的心 提交于 2019-11-30 03:20:36

问题


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

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

[[UIScreen mainScreen] setBrightness:0.5];

How do I do this in Swift?


回答1:


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

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

UIScreen.main.brightness = CGFloat(0.5)



回答2:


Actually in Swift 3 mainScreen was replaced with main, so proper code is:

UIScreen.main.brightness = CGFloat(0.5)


来源:https://stackoverflow.com/questions/24264673/adjust-the-main-screen-brightness-using-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!