ios-darkmode

Light and dark mode in swift

我怕爱的太早我们不能终老 提交于 2021-02-05 12:24:54
问题 I created images assets for dark and light mode called myImage. Set the image assets appearance to Any, Dark. The problem this code gets the same image even if the mode is light or dark. How can I get the code to select the correct image depending on light or dark mode? Thanks for your help. let image = UIImage(named: "image") let asset = image?.imageAsset let resolvedImage = asset?.image(with: traitCollection) If let image = resolvedImage { myButton.setImage(image, for: .normal) } 回答1: let

Light and dark mode in swift

冷暖自知 提交于 2021-02-05 12:22:10
问题 I created images assets for dark and light mode called myImage. Set the image assets appearance to Any, Dark. The problem this code gets the same image even if the mode is light or dark. How can I get the code to select the correct image depending on light or dark mode? Thanks for your help. let image = UIImage(named: "image") let asset = image?.imageAsset let resolvedImage = asset?.image(with: traitCollection) If let image = resolvedImage { myButton.setImage(image, for: .normal) } 回答1: let

SwiftUI: Dark mode not detected when testing on device

[亡魂溺海] 提交于 2021-01-28 11:12:41
问题 I'm am trying to achieve dark mode within my iOS application using SwiftUI: simple test would be to change the background colour. I have set up my colour set as seen below: ContentView.swift: import SwiftUI struct ContentView : View { @EnvironmentObject var session: SessionStore func getUser () { session.listen() } var body: some View { Group { if (session.session != nil) { VStack { WelcomeView() .background(Color("bg")) .edgesIgnoringSafeArea(.all) } } else { VStack { SigninView().transition

Change buttonStyle Modifier based on light or dark mode in SwiftUI

倾然丶 夕夏残阳落幕 提交于 2020-12-25 04:51:21
问题 I want to set Custom buttonStyle modifier for button for light and dark mode. How to change buttonStyle Modifier based on light or dark mode? I want to set Custom modifier for my button for light and dark mode. here is my button code, Button(action: { print("button tapped") }, label: { LinearGradient(gradient: Gradient(colors: [.darkBlueColor, .lightBlueColor]), startPoint: .top, endPoint: .bottom) .mask(Image(systemName: "ellipsis") .resizable() .aspectRatio(contentMode: .fit) ).frame(width:

How to switch programmatically to dark mode swift

社会主义新天地 提交于 2020-11-29 04:18:12
问题 How can I make a switch to change programatically to dark or light mode in my iOS app? I'm using Swift. 回答1: You can override the style for single views or view controller using the overrideUserInterfaceStyle property. But since the window is also a view, you can set that on your main window to force it into light or dark mode: window.overrideUserInterfaceStyle = .dark 来源: https://stackoverflow.com/questions/60171262/how-to-switch-programmatically-to-dark-mode-swift

Programmatically detect dark mode in SwiftUI to display appropriate Image

狂风中的少年 提交于 2020-05-26 11:16:26
问题 In Assets.xcassets , there is an ability to add additional images that will automatically switch based on the Appearances. This works well for static images but I'm trying to figure out how to do this for downloaded images. Is there a way to either set the dark mode version of an Image on init or is there a function in SwiftUI that will allow you to detect whether the current appearance is dark so that a different image URL can be served? 回答1: You can use @Environment(\.colorScheme) var

Detect if iOS13 Dark Mode is enabled from Flutter/Dart [duplicate]

淺唱寂寞╮ 提交于 2020-05-25 13:37:58
问题 This question already has answers here : How to check if Android or iOS dark mode is enabled in Flutter? (3 answers) Closed 2 days ago . I'm writing a Flutter app for Android and iOS which will change its style/theme based on iOS' Dark Mode status. Is there currently anything like a MediaQuery.isDarkModeEnabled in Flutter? There is a GitHub issue open here but the Flutter team must be overwhelmed in issues so I can't see this being implemented too soon. I can use 'traitCollection

Detect if iOS13 Dark Mode is enabled from Flutter/Dart [duplicate]

蓝咒 提交于 2020-05-25 13:33:16
问题 This question already has answers here : How to check if Android or iOS dark mode is enabled in Flutter? (3 answers) Closed 2 days ago . I'm writing a Flutter app for Android and iOS which will change its style/theme based on iOS' Dark Mode status. Is there currently anything like a MediaQuery.isDarkModeEnabled in Flutter? There is a GitHub issue open here but the Flutter team must be overwhelmed in issues so I can't see this being implemented too soon. I can use 'traitCollection

Detect if iOS13 Dark Mode is enabled from Flutter/Dart [duplicate]

点点圈 提交于 2020-05-25 13:33:11
问题 This question already has answers here : How to check if Android or iOS dark mode is enabled in Flutter? (3 answers) Closed 2 days ago . I'm writing a Flutter app for Android and iOS which will change its style/theme based on iOS' Dark Mode status. Is there currently anything like a MediaQuery.isDarkModeEnabled in Flutter? There is a GitHub issue open here but the Flutter team must be overwhelmed in issues so I can't see this being implemented too soon. I can use 'traitCollection

Implement dark mode switch in SwiftUI App

巧了我就是萌 提交于 2020-05-25 08:44:56
问题 I'm currently looking into Dark Mode in my App. While Dark Mode itself isn't much of a struggle because of my SwiftUI basis i'm struggling with the option to set the ColorScheme independent of the system ColorScheme. I found this in apples human interface guidelines and i'd like to implement this feature. (Link: Human Interface Guidelines) Any idea how to do this in SwiftUI? I found some hints towards @Environment but no further information on this topic. (Link: Last paragraph) 回答1: First you