Post

Replies

Boosts

Views

Activity

Reply to Don't understand this bug
Did you put the breakpoint on line 42? The code execution is stopping on line 42 because you or someone has set a breakpoint on that line. Just tap on the blue breakpoint indicator on line 42 and it should disable it or you can right click the indicator and delete the breakpoint.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’22
Reply to Using UINavigationBar standalone causes weird top attaching layout
class ViewController: UIViewController {     @IBOutlet weak var navigationBar: UINavigationBar!     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.         navigationBar.delegate = self     } } extension ViewController: UINavigationBarDelegate {     func position(for bar: UIBarPositioning) -> UIBarPosition {         return .topAttached     } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Feb ’22
Reply to Is it possible to dynamically update the currency formatting of SwiftUI TextField?
I think this works. Try on simulator. Preview gives unpredictable results. import SwiftUI struct Amount {     var value: Decimal     var currency: CurrencyCode } struct ContentView: View {     @State var amount = Amount(value: Decimal(), currency: .GBP)     var body: some View {         CurrencyAmount(title: "Some label", amount: $amount)     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView(amount: Amount(value: Decimal(), currency: .GBP))     } } struct CurrencyAmount: View {     let title: String     let prompt: String = ""     @Binding var amount: Amount     @State var currency: CurrencyCode = .GBP     var body: some View {         HStack {             Spacer(minLength: 80)             TextField(title, value: $amount.value, format: .currency(code: amount.currency.rawValue), prompt: Text(prompt))             CurrencyPicker(selected: $currency)             Spacer(minLength: 80)         }         .onChange(of: currency) { newValue in             amount.currency =  newValue         }     } } struct CurrencyPicker: View {     @Binding var selected: CurrencyCode     let label = "Currency"     var body: some View {         Picker(label, selection: $selected) {             ForEach(CurrencyCode.allCases) {                 Text($0.rawValue)                     .tag($0)             }         }     } } enum CurrencyCode: String, CaseIterable, Identifiable {     var id: String { self.rawValue }     case AUD, CAD, EUR, GBP, NZD, USD }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to UIListContentConfiguration text color during selection
For iOS 14, I think you have to subclass UICollectionViewListCell and override updateConfiguration(using state: UICellConfigurationState). It should work for iOS 15 also. let cellConfiguration = UICollectionView.CellRegistration<MyCell, String>....     override func updateConfiguration(using state: UICellConfigurationState) {         super.updateConfiguration(using: state)         guard var cConfig = self.contentConfiguration?.updated(for: state) as? UIListContentConfiguration else { return }         cConfig.textProperties.colorTransformer = UIConfigurationColorTransformer { color in             state.isSelected || state.isHighlighted ? .white : .black         }         cConfig.secondaryTextProperties.colorTransformer = UIConfigurationColorTransformer { color in             state.isSelected || state.isHighlighted ? .white : .black         }         self.contentConfiguration = cConfig         guard var bConfig = self.backgroundConfiguration?.updated(for: state) else { return }         bConfig.backgroundColorTransformer = UIConfigurationColorTransformer { color in             state.isSelected || state.isHighlighted ? .systemPink : .systemGray5         }         self.backgroundConfiguration = bConfig     } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’22
Reply to UIListContentConfiguration text color during selection
let cellConfigiuration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in         var contentConfiguration = UIListContentConfiguration.sidebarSubtitleCell()         contentConfiguration.text = "Primary Text: \(itemIdentifier)"         contentConfiguration.secondaryText = "Secondary Text"         cell.contentConfiguration = contentConfiguration         var backgroundConfiguration = UIBackgroundConfiguration.listSidebarCell()         backgroundConfiguration.backgroundColor = .systemGray5         cell.backgroundConfiguration = backgroundConfiguration         cell.configurationUpdateHandler = { cell, state in             guard var cConfig = cell.contentConfiguration?.updated(for: state) as? UIListContentConfiguration else { return }             cConfig.textProperties.colorTransformer = UIConfigurationColorTransformer { color in                 state.isSelected || state.isHighlighted ? .white : .black             }             cConfig.secondaryTextProperties.colorTransformer = UIConfigurationColorTransformer { color in                 state.isSelected || state.isHighlighted ? .white : .black             }             cell.contentConfiguration = cConfig             guard var bConfig = cell.backgroundConfiguration?.updated(for: state) else { return }             bConfig.backgroundColorTransformer = UIConfigurationColorTransformer { color in                 state.isSelected || state.isHighlighted ? .systemMint : .systemGray5             }             cell.backgroundConfiguration = bConfig         }     }
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’22
Reply to Where to put the animation
struct CardView: View {     @State var isFaceUp = false     var body: some View {         ZStack {             let shape = RoundedRectangle(cornerRadius: 20)             if isFaceUp {                 shape.fill().foregroundColor(.white)                 shape.stroke(lineWidth: 3)                 Text("😀").font(.system(size: 80))             } else {                 shape.fill()             }         }         .rotation3DEffect(Angle(degrees: isFaceUp ? 180 : 0), axis: (x: 0, y: 1, z: 0))         .animation(.spring(), value: isFaceUp)         .onTapGesture {             isFaceUp.toggle()         }     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Decoding JSON
struct OpenTotal: Decodable {     var total: Double?     var overOdds: Int?     var underOdds: Int? } struct CurrentTotal: Decodable {     var total: Double?     var overOdds: Int?     var underOdds: Int? }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22