Skip to content

Instantly share code, notes, and snippets.

@macward
macward / ContentView.swift
Last active October 18, 2022 04:26
Prevent dismiss sheet with a swipe
struct ContentView: View {
@State private var openSettingsSheet = false
var body: some View {
Button("Open Settings") {
openSettingsSheet.toggle()
}
.sheet(isPresented: $openSettingsSheet, content: SettingSheetView())
}
@macward
macward / AppDelegate+SetRootViewController.swift
Last active October 21, 2020 23:16
UIScene - Set root view controller #root #mainViewController #ViewController #navigation
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = {VIEW_CONTROLLER}
self.window = window
window.makeKeyAndVisible()
}
}
@macward
macward / UIColor+HEX.swift
Created October 21, 2020 23:14
UIColor RGB Extension #uicolor #extension #color
extension UIColor {
convenience init(rgb: UInt) {
self.init(red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(1.0))
}
}
@macward
macward / SearchBarBackground.swift
Last active June 12, 2020 04:19
Change Textfield Search bar background #searchbar #uisearchbar
// All verions
let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideSearchBar?.textColor = UIColor.AppColors.searchBarTextColor
textFieldInsideSearchBar?.backgroundColor = UIColor.AppColors.searchBarTextBackground
// Swift 4
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white]
// Swift 4.2 and iOS 12
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]