Hey there,
I use a UIMenu with UIActions to create a "submenu" on click of a button.
How can I colorize the title of the UIAction?
Example Code:
private static func createMenu(nc: TurboNavigationController) -> UIMenu {
let home = UIAction(
title: "Home",
image: UIImage(systemName: "house")
) { (_) in
let url = Constants.turboUrl("/")
nc.push(url: url)
}
let login = UIAction(
title: "Login",
image: UIImage(systemName: "lock.open")
) { (_) in
let url = Constants.turboUrl("/users/log_in")
nc.push(url: url)
}
let search = UIAction(
title: "Suche",
image: UIImage(systemName: "magnifyingglass")
) { (_) in
let url = Constants.turboUrl("/suche")
nc.push(url: url)
}
let settings = UIAction(
title: "Einstellungen",
image: UIImage(systemName: "person")
) { (_) in
let url = Constants.turboUrl("/app-settings")
nc.push(url: url)
}
let amount = UserDefaults.standard.string(forKey: currentBasketCountKey) ?? ""
let basket = UIAction(
title: "Warenkorb \(amount)",
image: UIImage(systemName: "bag")
) { (_) in
let url = Constants.turboUrl("/warenkorb")
nc.push(url: url)
}
let belege = UIAction(
title: "Belegauskunft",
image: UIImage(systemName: "doc.text")
) { (_) in
let url = Constants.turboUrl("/belegauskunft")
nc.push(url: url)
}
let scanner = UIAction(
title: "Scanner",
image: UIImage(systemName: "qrcode")
) { (_) in
let url = Constants.turboUrl("/scanner")
nc.push(url: url)
}
let ekToggleImage = UserDefaults.standard.string(forKey: ekPriceToggleKey) ?? "rectangle.badge.checkmark"
let netto = UIAction(
title: "Nettopreise ausblenden",
// checkmark.square || rectangle.badge.checkmark
image: UIImage(systemName: ekToggleImage)
) { (_) in
nc.session.webView.evaluateJavaScript("window.bridge.toggleEkHidden()")
let ekToggleImageNew = (ekToggleImage == "rectangle.badge.checkmark") ? "checkmark.square" : "rectangle.badge.checkmark"
UserDefaults.standard.set(ekToggleImageNew, forKey: ekPriceToggleKey)
let vc = nc.viewControllers.last
vc?.navigationItem.rightBarButtonItems = MainMenu.navigationItems(navController: nc)
}
let merkzettel = UIAction(
title: "Merkzettel",
image: UIImage(systemName: "list.bullet")
) { (_) in
let url = Constants.turboUrl("/merkzettel")
nc.push(url: url)
}
let isSignedIn = LoginApi.isLoggedIn()
let isLiveSystem = Constants.turboPath("/") == "https://app.***.de/"
let menuActions = [
home,
search,
basket,
belege,
merkzettel,
scanner,
isSignedIn ? nil : login,
!isLiveSystem ? settings : nil,
isSignedIn ? netto : nil
]
let addNewMenu = UIMenu(
title: "",
// Compact map discards all nil values
children: menuActions.compactMap { $0 }
)
return addNewMenu
}