Post

Replies

Boosts

Views

Activity

Reply to CollectionView class doesn't have the delegate property?
I tested in a test project, and it works (I get valid references for dataSource and delegate). But in my case, no loadView, so I initialise testVC in viewDidLoad. Try to move   let flowLayout = UICollectionViewFlowLayout()   let photoCollectionViewLayoutFrame = CGRect(x: 0, y: 0, width: scrollView.bounds.width, height: CGFloat(150))   testCV = UICollectionView(frame: photoCollectionViewLayoutFrame, collectionViewLayout: flowLayout) to viewDidLoad. Why do you overload loadView() ? There are a lot of warnings in loadView() doc when doing so: If you use Interface Builder to create your views and initialize the view controller, you must not override this method. You can override this method in order to create your views manually. If you choose to do so, assign the root view of your view hierarchy to the view property. The views you create should be unique instances and should not be shared with any other view controller object. Your custom implementation of this method should not call super. If you want to perform any additional initialization of your views, do so in the viewDidLoad()method.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to size of custom component
My understanding is qualified YES. the tappable region should be 44*44 at least but the visible part of it could be smaller (not too small however, so that user can still understand it). Note that HIG are guidelines, for the good of all, not strict requirements. PS: is your question to Apple ? If so, the forum is not the best place to do it. You should better contact support (even though I fear they can only repeat what HIG says).
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21
Reply to ProGuard equivalent for iOS
Take care of the risk of rejection when submitting to AppStore: h t t p s : / / github. com/Adyen/adyen-3ds2-ios/issues/3 sending it to the App Store, we got rejected based on Guideline 2.3.1: We discovered that your app contains obfuscated code, selector mangling, or features meant to subvert the App Review process by changing this app's concept after approval to the App Store.
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’21
Reply to Text like PlaceHolder
As Beatles would have song, yes, you can display anything you want… More seriously, you have to consider: 1 that "placeholder" part must be gray: hence need attributedString 2 that you have to type text at the place of the first placeHolder char : need to force the insertion point 3 at each character typed, substitute in the String if valid ; use :     func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 4 to insert space at appropriate places 5 that user must understand what is expected. But it is possible. You'll probably have to subclass UITextField. Another way to do this is add a label (smaller fonts) atop of the textField. make this label appear as soon as you've started to type. display " 31 0M YYYY " only in the label; in textField, you would have " 31 0" That would avoid step 2 and make step 5 easier Yet another way: create 3 textFields for Day, Month and year have placeholders in each automatically jump to next textField once one is complete.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to IP restricted App
@PhilFromTheMinion If I understand correctly, that was a requirement only for the review team. May be you could authorise access from some specific IP address (ask the reviewer to provide it) and provide a password to unlock access from this address…
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’21
Reply to picker SwiftUI avec des float
Quelques précisions seraient utiles: Que contient minutes ? Où sont affichées les valeurs 10 à 16 ? (s'agit il de minutes ?) Je ne vois pas la division par 10 Mais quelque chose comme ceci devrait donner le résultat attendu (peut être dans l'ordre inverse): Picker(selection: self.$minuteChoisie, label: Text("")){ ForEach(0 ..< self.minutes.count){ index in let val = Float(self.minutes[index]) / 10 let valString = String(format: "%.01f", val) Text("\(valString)") .tag(index) } } Pour l'avoir dans le bon ordre: Picker(selection: self.$minuteChoisie, label: Text("")){ ForEach(0 ..< self.minutes.count) { index in let val = Float(self.minutes[self.minutes.count-index-1]) / 10 let valString = String(format: "%.01f", val) Text("\(valString)") .tag(index) } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to No suitable image found.
If you remove the IBDesignable statements in code, does it work ? Or is the problem more general of not being able to open storyboards ? Have a look here, seems a similar problem. https://stackoverflow.com/questions/53114398/xcode-simulator-cymemdef-dylib-mach-o-but-not-built-for-ios-simulator/53235872
Aug ’21
Reply to Text like PlaceHolder
Well, I think I found a much simpler solution: create a background image with the text for placeholder then, when you type, the new text will appear just over the placeholder. I've left some links to additional information if needed Here is a sample code: class TextFieldDynPlaceHolder: UITextField, UITextFieldDelegate { let defaultPlaceHolder = "DD MM YYYY" var thePlaceHolder : String! // To be set at call func commonInit() { delegate = self thePlaceHolder = defaultPlaceHolder // "DD MM YYYY" self.background = image(from: thePlaceHolder) // Need to set borderStyle: https://stackoverflow.com/questions/64057501/how-to-fix-uitextfield-background-image-not-displayed-after-ios14 self.borderStyle = .line } // https://stackoverflow.com/questions/759658/uitextview-background-image override init(frame: CGRect) { super.init(frame: frame) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) commonInit() } // https://stackoverflow.com/questions/51100121/how-to-generate-an-uiimage-from-custom-text-in-swift func image(from text: String?) -> UIImage? { let frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) let nameLabel = UILabel(frame: frame) nameLabel.textAlignment = .left nameLabel.backgroundColor = .systemBackground nameLabel.textColor = .placeholderText // .darkGray if .placeholderText is too light nameLabel.font = self.font nameLabel.text = text UIGraphicsBeginImageContext(frame.size) if let currentContext = UIGraphicsGetCurrentContext() { nameLabel.layer.render(in: currentContext) let nameImage = UIGraphicsGetImageFromCurrentImageContext() return nameImage } return nil } // Check we typed digits or space or backspace func textFieldDidChangeSelection(_ textField: UITextField) { var trimmedPlaceHolder = defaultPlaceHolder if let typedText = textField.text { for c in typedText.unicodeScalars { if !CharacterSet.decimalDigits.contains(c) && !CharacterSet.whitespaces.contains(c) { // And play a beep textField.text = String(textField.text!.dropLast()) } } } if let typed = textField.text?.count, typed > 0 { trimmedPlaceHolder = String(defaultPlaceHolder.dropFirst(typed)) // And we replace with spaces for _ in 0..<typed { trimmedPlaceHolder = " " + trimmedPlaceHolder } self.background = image(from: trimmedPlaceHolder) } else { self.background = image(from: trimmedPlaceHolder) } } // Could check here the complete date Validity func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { return true // Here you could test the validity of entry as a Date } } To test it: in storyboard, create a UITextField and declare as TextFieldDynPlaceHolder select a fixed width font (otherwise, date will nor superpose placeholder) set its width to what you need (don't let it free, otherwise placeholder may not show) in the controller, set thePlaceHolder to the date you need May set thePlaceHolder in commonInit() (change from = "DD MM YYYY") If that works, thanks to tell as well as to post any improvement you may find, like better testing the validity of what was typed. And then don't forget to close the thread.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Trailing closure passed to parameter of type 'Int' that does not accept a closure
Which line exactly ? Is it line 3 or 4 ? If so, please show how onboardingData and OnboardingCard are defined. Otherwise tell exactly where you get the error. 1. VStack { 2. TabView { 3. ForEach(onboardingData) { onboardingItem in 4. OnboardingCard(onboardingItem: onboardingItem) 5. } 6. } 7. .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic)) 8. .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode: .always)) 9. .foregroundColor(.white) 10. }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Text like PlaceHolder
In previous code, there are some issues with darkmode: placeholder hardly readable (a known bug in iOS in dark mode) when switching mode, colors did not immediately adjust. Here is the improved code: class TextFieldDynPlaceHolder: UITextField, UITextFieldDelegate { let defaultPlaceHolder = "DD MM YYYY" // Could set it as IBInspectable property var thePlaceHolder : String! // To be set at call // --------------------- commonInit ---------------------------------------------------- // Description: set the placeholder from text // Parameters // Comments: // Need to set borderStyle (bug in iOS): https://stackoverflow.com/questions/64057501/how-to-fix-uitextfield-background-image-not-displayed-after-ios14 // ------------------------------------------------------------------------------------------------- func commonInit() { delegate = self thePlaceHolder = defaultPlaceHolder // "DD MM YYYY" self.background = image(from: thePlaceHolder) self.borderStyle = .line } override init(frame: CGRect) { super.init(frame: frame) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) commonInit() } // --------------------- traitCollectionDidChange ------------------------------------------- // Description: Adjust colors when switching mode light / dark. // Parameters // previousTraitCollection: UITraitCollection? // Comments: // ------------------------------------------------------------------------------------------------- override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) adaptPlaceHolder(self) } // --------------------- image ------------------------------------------- // Description: Create image from a text. // Parameters // from text: String? // Comments: // https://stackoverflow.com/questions/51100121/how-to-generate-an-uiimage-from-custom-text-in-swift // In fact, placeholderText unreadable in darkMode. https://stackoverflow.com/questions/58478744/uitextfield-placeholder-text-is-unreadable-in-ios13-dark-mode // ------------------------------------------------------------------------------------------------- func image(from text: String?) -> UIImage? { let frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) let nameLabel = UILabel(frame: frame) nameLabel.textAlignment = .left nameLabel.backgroundColor = .systemBackground if traitCollection.userInterfaceStyle == .light { nameLabel.textColor = .placeholderText // .darkGray if .placeholderText is too light } else { nameLabel.textColor = .systemGray } nameLabel.font = self.font nameLabel.text = text UIGraphicsBeginImageContext(frame.size) if let currentContext = UIGraphicsGetCurrentContext() { nameLabel.layer.render(in: currentContext) let nameImage = UIGraphicsGetImageFromCurrentImageContext() return nameImage } return nil } // --------------------- adaptPlaceHolder -------------------------------------- // Description: Trims placeHolder text when first characters typed ; rebuilds image. // Parameters // textField: UITextField // Comments: // ------------------------------------------------------------------------------------------------- func adaptPlaceHolder(_ textField: UITextField) { var trimmedPlaceHolder = defaultPlaceHolder if let typed = textField.text?.count, typed > 0 { trimmedPlaceHolder = String(defaultPlaceHolder.dropFirst(typed)) // And we replace with spaces for _ in 0..<typed { trimmedPlaceHolder = " " + trimmedPlaceHolder } self.background = image(from: trimmedPlaceHolder) } else { self.background = image(from: trimmedPlaceHolder) } } // --------------------- adaptPlaceHolder -------------------------------------- // Description: redraws placeHolder image when characters typed and checks characters are decimals // Parameters // textField: UITextField // Comments: // ------------------------------------------------------------------------------------------------- func textFieldDidChangeSelection(_ textField: UITextField) { if let typedText = textField.text { for c in typedText.unicodeScalars { if !CharacterSet.decimalDigits.contains(c) && !CharacterSet.whitespaces.contains(c) { // And play a beep textField.text = String(textField.text!.dropLast()) } } } adaptPlaceHolder(textField) } // --------------------- textField -------------------------------------- // Description: test the validity of entry (as a Date for instance) // Parameters // textField: UITextField // shouldChangeCharactersIn range: NSRange // replacementString string: String // Comments: // To be implemented // ------------------------------------------------------------------------------------------------- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { return true } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Trailing closure passed to parameter of type 'Int' that does not accept a closure
Doc states : Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item. like in TabView { Text("The First Tab") .badge(10) .tabItem { Image(systemName: "1.square.fill") Text("First") } That's not the case with your code: you return OnboardingCard ForEach(onboardingData) { onboardingItem in OnboardingCard(onboardingItem: onboardingItem) } What is the purpose of VStack for TabView ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to CollectionView class doesn't have the delegate property?
I tested in a test project, and it works (I get valid references for dataSource and delegate). But in my case, no loadView, so I initialise testVC in viewDidLoad. Try to move   let flowLayout = UICollectionViewFlowLayout()   let photoCollectionViewLayoutFrame = CGRect(x: 0, y: 0, width: scrollView.bounds.width, height: CGFloat(150))   testCV = UICollectionView(frame: photoCollectionViewLayoutFrame, collectionViewLayout: flowLayout) to viewDidLoad. Why do you overload loadView() ? There are a lot of warnings in loadView() doc when doing so: If you use Interface Builder to create your views and initialize the view controller, you must not override this method. You can override this method in order to create your views manually. If you choose to do so, assign the root view of your view hierarchy to the view property. The views you create should be unique instances and should not be shared with any other view controller object. Your custom implementation of this method should not call super. If you want to perform any additional initialization of your views, do so in the viewDidLoad()method.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to size of custom component
My understanding is qualified YES. the tappable region should be 44*44 at least but the visible part of it could be smaller (not too small however, so that user can still understand it). Note that HIG are guidelines, for the good of all, not strict requirements. PS: is your question to Apple ? If so, the forum is not the best place to do it. You should better contact support (even though I fear they can only repeat what HIG says).
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to ProGuard equivalent for iOS
Take care of the risk of rejection when submitting to AppStore: h t t p s : / / github. com/Adyen/adyen-3ds2-ios/issues/3 sending it to the App Store, we got rejected based on Guideline 2.3.1: We discovered that your app contains obfuscated code, selector mangling, or features meant to subvert the App Review process by changing this app's concept after approval to the App Store.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Login with phone number and password in Firebase
Did you ask the question to Firebase or on their forum ? You may get more there.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Text like PlaceHolder
As Beatles would have song, yes, you can display anything you want… More seriously, you have to consider: 1 that "placeholder" part must be gray: hence need attributedString 2 that you have to type text at the place of the first placeHolder char : need to force the insertion point 3 at each character typed, substitute in the String if valid ; use :     func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 4 to insert space at appropriate places 5 that user must understand what is expected. But it is possible. You'll probably have to subclass UITextField. Another way to do this is add a label (smaller fonts) atop of the textField. make this label appear as soon as you've started to type. display " 31 0M YYYY " only in the label; in textField, you would have " 31 0" That would avoid step 2 and make step 5 easier Yet another way: create 3 textFields for Day, Month and year have placeholders in each automatically jump to next textField once one is complete.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to IP restricted App
@PhilFromTheMinion If I understand correctly, that was a requirement only for the review team. May be you could authorise access from some specific IP address (ask the reviewer to provide it) and provide a password to unlock access from this address…
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to picker SwiftUI avec des float
Quelques précisions seraient utiles: Que contient minutes ? Où sont affichées les valeurs 10 à 16 ? (s'agit il de minutes ?) Je ne vois pas la division par 10 Mais quelque chose comme ceci devrait donner le résultat attendu (peut être dans l'ordre inverse): Picker(selection: self.$minuteChoisie, label: Text("")){ ForEach(0 ..< self.minutes.count){ index in let val = Float(self.minutes[index]) / 10 let valString = String(format: "%.01f", val) Text("\(valString)") .tag(index) } } Pour l'avoir dans le bon ordre: Picker(selection: self.$minuteChoisie, label: Text("")){ ForEach(0 ..< self.minutes.count) { index in let val = Float(self.minutes[self.minutes.count-index-1]) / 10 let valString = String(format: "%.01f", val) Text("\(valString)") .tag(index) } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Is it legal to decompile Apple Open Source components?
That's not a legal opinion, take care, just some thoughts. Have you signed a licence agreement for those specific open source software ? What does it say ? Is it open source (then why do you need to decompile?) or open libraries? In the latter case, it is probably illegal to decompile.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to No suitable image found.
If you remove the IBDesignable statements in code, does it work ? Or is the problem more general of not being able to open storyboards ? Have a look here, seems a similar problem. https://stackoverflow.com/questions/53114398/xcode-simulator-cymemdef-dylib-mach-o-but-not-built-for-ios-simulator/53235872
Replies
Boosts
Views
Activity
Aug ’21
Reply to Beta 3 Swiftui Table Core Data Error
@workingdogintokyo You cannot delete ! But, if you do it now, before the post is 1 hour old, you can edit the post or the comment (button with ! inside) and replace it by a text like "Message deleted". But do it rapidly…
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Text like PlaceHolder
Well, I think I found a much simpler solution: create a background image with the text for placeholder then, when you type, the new text will appear just over the placeholder. I've left some links to additional information if needed Here is a sample code: class TextFieldDynPlaceHolder: UITextField, UITextFieldDelegate { let defaultPlaceHolder = "DD MM YYYY" var thePlaceHolder : String! // To be set at call func commonInit() { delegate = self thePlaceHolder = defaultPlaceHolder // "DD MM YYYY" self.background = image(from: thePlaceHolder) // Need to set borderStyle: https://stackoverflow.com/questions/64057501/how-to-fix-uitextfield-background-image-not-displayed-after-ios14 self.borderStyle = .line } // https://stackoverflow.com/questions/759658/uitextview-background-image override init(frame: CGRect) { super.init(frame: frame) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) commonInit() } // https://stackoverflow.com/questions/51100121/how-to-generate-an-uiimage-from-custom-text-in-swift func image(from text: String?) -> UIImage? { let frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) let nameLabel = UILabel(frame: frame) nameLabel.textAlignment = .left nameLabel.backgroundColor = .systemBackground nameLabel.textColor = .placeholderText // .darkGray if .placeholderText is too light nameLabel.font = self.font nameLabel.text = text UIGraphicsBeginImageContext(frame.size) if let currentContext = UIGraphicsGetCurrentContext() { nameLabel.layer.render(in: currentContext) let nameImage = UIGraphicsGetImageFromCurrentImageContext() return nameImage } return nil } // Check we typed digits or space or backspace func textFieldDidChangeSelection(_ textField: UITextField) { var trimmedPlaceHolder = defaultPlaceHolder if let typedText = textField.text { for c in typedText.unicodeScalars { if !CharacterSet.decimalDigits.contains(c) && !CharacterSet.whitespaces.contains(c) { // And play a beep textField.text = String(textField.text!.dropLast()) } } } if let typed = textField.text?.count, typed > 0 { trimmedPlaceHolder = String(defaultPlaceHolder.dropFirst(typed)) // And we replace with spaces for _ in 0..<typed { trimmedPlaceHolder = " " + trimmedPlaceHolder } self.background = image(from: trimmedPlaceHolder) } else { self.background = image(from: trimmedPlaceHolder) } } // Could check here the complete date Validity func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { return true // Here you could test the validity of entry as a Date } } To test it: in storyboard, create a UITextField and declare as TextFieldDynPlaceHolder select a fixed width font (otherwise, date will nor superpose placeholder) set its width to what you need (don't let it free, otherwise placeholder may not show) in the controller, set thePlaceHolder to the date you need May set thePlaceHolder in commonInit() (change from = "DD MM YYYY") If that works, thanks to tell as well as to post any improvement you may find, like better testing the validity of what was typed. And then don't forget to close the thread.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Need Help Transfer Data From Button
Check the connection from button in IB to the IBAction. In fact, remove the connection and rebuild. Note that the name of func should start with lowercase camButtonA.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Trailing closure passed to parameter of type 'Int' that does not accept a closure
Which line exactly ? Is it line 3 or 4 ? If so, please show how onboardingData and OnboardingCard are defined. Otherwise tell exactly where you get the error. 1. VStack { 2. TabView { 3. ForEach(onboardingData) { onboardingItem in 4. OnboardingCard(onboardingItem: onboardingItem) 5. } 6. } 7. .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic)) 8. .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode: .always)) 9. .foregroundColor(.white) 10. }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Text like PlaceHolder
In previous code, there are some issues with darkmode: placeholder hardly readable (a known bug in iOS in dark mode) when switching mode, colors did not immediately adjust. Here is the improved code: class TextFieldDynPlaceHolder: UITextField, UITextFieldDelegate { let defaultPlaceHolder = "DD MM YYYY" // Could set it as IBInspectable property var thePlaceHolder : String! // To be set at call // --------------------- commonInit ---------------------------------------------------- // Description: set the placeholder from text // Parameters // Comments: // Need to set borderStyle (bug in iOS): https://stackoverflow.com/questions/64057501/how-to-fix-uitextfield-background-image-not-displayed-after-ios14 // ------------------------------------------------------------------------------------------------- func commonInit() { delegate = self thePlaceHolder = defaultPlaceHolder // "DD MM YYYY" self.background = image(from: thePlaceHolder) self.borderStyle = .line } override init(frame: CGRect) { super.init(frame: frame) commonInit() } required init?(coder: NSCoder) { super.init(coder: coder) commonInit() } // --------------------- traitCollectionDidChange ------------------------------------------- // Description: Adjust colors when switching mode light / dark. // Parameters // previousTraitCollection: UITraitCollection? // Comments: // ------------------------------------------------------------------------------------------------- override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) adaptPlaceHolder(self) } // --------------------- image ------------------------------------------- // Description: Create image from a text. // Parameters // from text: String? // Comments: // https://stackoverflow.com/questions/51100121/how-to-generate-an-uiimage-from-custom-text-in-swift // In fact, placeholderText unreadable in darkMode. https://stackoverflow.com/questions/58478744/uitextfield-placeholder-text-is-unreadable-in-ios13-dark-mode // ------------------------------------------------------------------------------------------------- func image(from text: String?) -> UIImage? { let frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) let nameLabel = UILabel(frame: frame) nameLabel.textAlignment = .left nameLabel.backgroundColor = .systemBackground if traitCollection.userInterfaceStyle == .light { nameLabel.textColor = .placeholderText // .darkGray if .placeholderText is too light } else { nameLabel.textColor = .systemGray } nameLabel.font = self.font nameLabel.text = text UIGraphicsBeginImageContext(frame.size) if let currentContext = UIGraphicsGetCurrentContext() { nameLabel.layer.render(in: currentContext) let nameImage = UIGraphicsGetImageFromCurrentImageContext() return nameImage } return nil } // --------------------- adaptPlaceHolder -------------------------------------- // Description: Trims placeHolder text when first characters typed ; rebuilds image. // Parameters // textField: UITextField // Comments: // ------------------------------------------------------------------------------------------------- func adaptPlaceHolder(_ textField: UITextField) { var trimmedPlaceHolder = defaultPlaceHolder if let typed = textField.text?.count, typed > 0 { trimmedPlaceHolder = String(defaultPlaceHolder.dropFirst(typed)) // And we replace with spaces for _ in 0..<typed { trimmedPlaceHolder = " " + trimmedPlaceHolder } self.background = image(from: trimmedPlaceHolder) } else { self.background = image(from: trimmedPlaceHolder) } } // --------------------- adaptPlaceHolder -------------------------------------- // Description: redraws placeHolder image when characters typed and checks characters are decimals // Parameters // textField: UITextField // Comments: // ------------------------------------------------------------------------------------------------- func textFieldDidChangeSelection(_ textField: UITextField) { if let typedText = textField.text { for c in typedText.unicodeScalars { if !CharacterSet.decimalDigits.contains(c) && !CharacterSet.whitespaces.contains(c) { // And play a beep textField.text = String(textField.text!.dropLast()) } } } adaptPlaceHolder(textField) } // --------------------- textField -------------------------------------- // Description: test the validity of entry (as a Date for instance) // Parameters // textField: UITextField // shouldChangeCharactersIn range: NSRange // replacementString string: String // Comments: // To be implemented // ------------------------------------------------------------------------------------------------- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { return true } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Trailing closure passed to parameter of type 'Int' that does not accept a closure
Doc states : Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item. like in TabView { Text("The First Tab") .badge(10) .tabItem { Image(systemName: "1.square.fill") Text("First") } That's not the case with your code: you return OnboardingCard ForEach(onboardingData) { onboardingItem in OnboardingCard(onboardingItem: onboardingItem) } What is the purpose of VStack for TabView ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21