-
[UIKit] iOS 앱 화면 밝기 조정하기/iOS 📱 2025. 2. 13. 22:05반응형
하드웨어 기반 디스플레이와 관련된 속성을 정의하는 객체인 UIScreen 에서 사용
UIScreen 객체는 iOS, iPadOS 또는 tvOS 장치에 연결된 화면에 대한 정보를 제공합니다. 모든 iOS 및 iPadOS 장치에는 통합 디스플레이에 대한 정보가 있는 화면 객체와 연결된 디스플레이에 대한 0개 이상의 화면 객체가 있습니다. tvOS 장치에는 장치에 연결된 텔레비전을 나타내는 화면 객체가 있습니다. visionOS에서 실행되는 호환되는 iPad 또는 iPhone 앱에서, 앱을 구성하기 위해 화면 관련 속성에 의존하지 마십시오.
@MainActor var brightness: CGFloat { get set }
이 속성은 메인 화면에서만 지원됩니다. 이 속성의 값은 0.0과 1.0 사이의 숫자이며, 여기서 0.0은 최소 밝기이고 1.0은 최대 밝기입니다.
밝기 변경은 그 사람이 그 전에 당신의 앱을 닫더라도 그 사람이 기기를 잠글 때까지 유효다음에 장치를 잠금 해제할 때, 시스템은 설정 또는 제어 센터에서 밝기 설정을 원래 값으로 복원
visionOS에서 이 속성을 설정하면 아무런 효과가 없음override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground let currentBrightness = UIScreen.main.brightness print("현재 밝기: \(currentBrightness)") // 밝기 조절 버튼 추가 Brightness.allCases.forEach { let button = UIButton(type: .system) button.tag = $0.rawValue button.setTitle("\($0.description) 밝기 조절", for: .normal) button.addTarget(self, action: #selector(adjustBrightness), for: .touchUpInside) button.frame = CGRect(x: 50, y: 100 + (50 * $0.rawValue), width: 200, height: 50) view.addSubview(button) } } @objc func adjustBrightness(_ sender: UIButton) { guard let brigthness = Brightness(rawValue: sender.tag) else { return } UIScreen.main.brightness = brigthness.value print("밝기를 \(brigthness.description)로 설정했습니다.") }
https://developer.apple.com/documentation/uikit/uiscreen
UIScreen | Apple Developer Documentation
An object that defines the properties associated with a hardware-based display.
developer.apple.com
https://developer.apple.com/documentation/uikit/uiscreen/brightness
brightness | Apple Developer Documentation
The brightness level of the screen.
developer.apple.com
' > iOS 📱' 카테고리의 다른 글
[UIKit] UIKit의 스토리보드 Preview 적용하기(Storyboard, Preview, 미리보기) (0) 2024.12.08 [iOS] Meet AccessorySetupKit 정리 (0) 2024.06.14 [iOS] Storyboard에서 accessibilityIdentifier 설정하기 (User Defined Runtime Attributes) (0) 2024.03.13 [iOS] HTTP 통신 허용 (0) 2023.11.04 [iOS] class가 NSObject를 상속받아야할 때 (NSObjectProtocol) (1) 2023.11.04