Post

Replies

Boosts

Views

Activity

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 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 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 URLSession dataTask Does not fetch data
For https://earthquake.phivolcs.dost.gov.ph header is <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> For https://earthquake.phivolcs.dost.gov.ph/2022_Earthquake_Information/September/2022_0922_1059_B2.html header is <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> Look at the charset
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’22
Reply to How to resize items in collection view to perfectly fit bigger screen sizes?
If you want to keep the itemSize same across devices you should consider calculating the interitemspacing based on the collection view content width. If you want to keep the interitemspacing same then calculate the itemSize based on the collection view content width. This is assuming you always want the same number of items on each row. Alternately consider using Compositional Layout which provides more flexibility in configuring collection view layouts. Compositional Layout
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’22
Reply to The number on the screen does not change when the variable changes.
import SwiftUI struct S1: View { @State var aa = 0 var body: some View { TabView{ S2(aa: $aa) .tabItem { Image(systemName: "person.fill") Text("1") } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.ultraThickMaterial, for: .tabBar) S3(aa: $aa) .tabItem { Image(systemName: "person.fill") Text("2") } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.ultraThickMaterial, for: .tabBar) } } } struct S1_Previews: PreviewProvider { static var previews: some View { S1() } } import SwiftUI struct S2: View { @State var bb = 0 @Binding var aa: Int var body: some View { VStack{ HStack{ Button { aa += 1 if aa > bb { bb += 1 } } label: { Text("+") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } Button { aa -= 1 if aa < bb { bb -= 1 } } label: { Text("-") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } } Text(String(bb)) .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility3) } .onChange(of: aa) { newValue in if aa > bb { bb += 1 } else if aa < bb { bb -= 1 } } } } struct S2_Previews: PreviewProvider { static var previews: some View { S2(aa: .constant(0)) } } import SwiftUI struct S3: View { @Binding var aa: Int var body: some View { HStack{ Button { aa += 1 } label: { Text("+") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } Button { aa -= 1 } label: { Text("-") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } } } } struct S3_Previews: PreviewProvider { static var previews: some View { S3(aa: .constant(0)) } }
Mar ’23
Reply to Animation duration won't change
What do you mean by moving layers around? Can you give an example?
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to iOS 15 crash at UICollectionView
In viewWillAppear, you are trying to trying to scroll to the first item? Does your collectionView have any data at this point?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jan ’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:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Resume app from where it was sent to background.
Check this out -> Sample App
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Feb ’22
Reply to Can You Store FaceID Data On Your Own Database?
Nope
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’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:
Replies
Boosts
Views
Activity
Feb ’22
Reply to How does async/await work?
All the code you want to execute after refreshResources should be inside the Task block.
Replies
Boosts
Views
Activity
Jun ’22
Reply to NavigationBar Back Button Color iOS 16
You can set accentColor on the NavigationStack
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’22
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:
Replies
Boosts
Views
Activity
Sep ’22
Reply to Setting background color of whole View in SwiftUI when using NavigationView
Here is a screenshot
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to How to set the navigation bar's back bar button without using UIBarButtonItem.appearance
Have you tried using UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self])
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to URLSession dataTask Does not fetch data
For https://earthquake.phivolcs.dost.gov.ph header is <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> For https://earthquake.phivolcs.dost.gov.ph/2022_Earthquake_Information/September/2022_0922_1059_B2.html header is <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> Look at the charset
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to How to resize items in collection view to perfectly fit bigger screen sizes?
If you want to keep the itemSize same across devices you should consider calculating the interitemspacing based on the collection view content width. If you want to keep the interitemspacing same then calculate the itemSize based on the collection view content width. This is assuming you always want the same number of items on each row. Alternately consider using Compositional Layout which provides more flexibility in configuring collection view layouts. Compositional Layout
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to The number on the screen does not change when the variable changes.
You should make aa a State var aa = 0 in S1 and make it a @Binding var aa: Int in both S2 & S3.
Replies
Boosts
Views
Activity
Mar ’23
Reply to The number on the screen does not change when the variable changes.
import SwiftUI struct S1: View { @State var aa = 0 var body: some View { TabView{ S2(aa: $aa) .tabItem { Image(systemName: "person.fill") Text("1") } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.ultraThickMaterial, for: .tabBar) S3(aa: $aa) .tabItem { Image(systemName: "person.fill") Text("2") } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.ultraThickMaterial, for: .tabBar) } } } struct S1_Previews: PreviewProvider { static var previews: some View { S1() } } import SwiftUI struct S2: View { @State var bb = 0 @Binding var aa: Int var body: some View { VStack{ HStack{ Button { aa += 1 if aa > bb { bb += 1 } } label: { Text("+") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } Button { aa -= 1 if aa < bb { bb -= 1 } } label: { Text("-") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } } Text(String(bb)) .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility3) } .onChange(of: aa) { newValue in if aa > bb { bb += 1 } else if aa < bb { bb -= 1 } } } } struct S2_Previews: PreviewProvider { static var previews: some View { S2(aa: .constant(0)) } } import SwiftUI struct S3: View { @Binding var aa: Int var body: some View { HStack{ Button { aa += 1 } label: { Text("+") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } Button { aa -= 1 } label: { Text("-") .frame(width: 140, height: 50) .background { RoundedRectangle(cornerRadius: 15, style: .continuous) .fill(Color(red: 0.888, green: 0.536, blue: 0.785)) .frame(width: 140, height: 50) } .foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69)) .multilineTextAlignment(.center) .bold() .dynamicTypeSize(.accessibility1) } } } } struct S3_Previews: PreviewProvider { static var previews: some View { S3(aa: .constant(0)) } }
Replies
Boosts
Views
Activity
Mar ’23