Post

Replies

Boosts

Views

Activity

TextView Data Detectors : Flight Information
I have a textView in the Main storyboard where I've enabled the data detector for Flight Number and disabled editing. When the textView is presented, the user can tap the flight number link. It displays a dialog with a map and a UIMenu for Preview Flight. However, when I select Preview Flight, it shows nothing but 'Flight information unavailable'. I tried the same flight number on Apple Notes, and it works fine.
0
0
206
Jul ’24
QRCode for vCard
The project is to create QRCode for digital vCard. I've generated QRCode for following contact fields and be able to be read by iPhone camera: Name(N:), Telephone(TEL:), Email(Email:), url(URL:) and Note(NOTE:) But no luck on fields: Company, Address, Social Profile and photo: textToQRCode = "BEGIN:VCARD\n" +  "N:\(lastName);\(firstName)\n" + "TEL:\(phoneNumber)\n" + "Email:\(email)\n" + "NOTE:\(notes)\n" + "END:VCARD"  Any suggestions? Thanks!
10
0
2.3k
Nov ’22
cell.defaultContentConfiguration() vs cell.textLabel
For a tableView: I try to change my code from using cell.textLabel to cell.contentConfiguration, we can't get the same result as before (using cell.textLabel), I like to keep the row heigh at 20, the old code display nicely, but the new code won't be able to show it at all unless I use row height 40. Here's the code: import UIKit var fruites = ["Apple","Orange","PineApple", "Water Melon", "Banana"] class ViewController: UIViewController {     @IBOutlet weak var tblTableViewA: UITableView!     override func viewDidLoad() {         super.viewDidLoad()         tblTableViewA.dataSource = self         tblTableViewA.delegate = self     } } extension ViewController: UITableViewDataSource {     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return fruites.count     }     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let cell = tableView.dequeueReusableCell(withIdentifier: "CellA", for: indexPath)         let fruit = fruites[indexPath.row]         // New code does not display right, content does not display properly like old code. when row height = 20, it won't even show.         /*         var content = cell.defaultContentConfiguration()         content.textProperties.adjustsFontSizeToFitWidth = true         content.text = fruit         cell.contentConfiguration = content         */         // Old code works perfect         cell.textLabel?.adjustsFontSizeToFitWidth = true         cell.textLabel!.text = fruit         return cell     } extension ViewController: UITableViewDelegate {     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat     {         return 20 //CGFloat(20)     } } Thanks in advance!
1
0
1.3k
May ’22
How to save and load text & images in DocumentsDirectory
Here's basic code of my ToDo App: Data: struct ToDo: Codable {     var title: String     var isCompleted: Bool     var dateCreated: Date     var notes:  String      static let DocumentsDirectory =     FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!     static let ArchiveURL = DocumentsDirectory.appendingPathComponent("todos") .appendingPathExtension("plist")     static func loadToDos() -> [ToDo]? {         guard let codedToDos = try? Data(contentsOf: ArchiveURL) else {return nil}         let propertyListDecoder = PropertyListDecoder()         return try? propertyListDecoder.decode(Array<ToDo>.self, from: codedToDos)     }     static func saveToDos(_ todos: [ToDo]) {         let propertyListEncoder = PropertyListEncoder()         let codedToDos = try? propertyListEncoder.encode(todos)         try? codedToDos?.write(to: ArchiveURL,           options: .noFileProtection)     }    I have a tableViewController to display the data's detail, there's a noteTextView (textView) for editing/adding the todo.note. There's a Camera Button allows user to insert the images into (textView) todo.note using NSTextAttachment(): internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {         let attachment = NSTextAttachment()         let image = info[.originalImage] as! UIImage         attachment.image = image         //Resize Photo to fit in noteTextView: calculate new size so want a litter space on the right of image         let newImageWidth = (noteTextView.bounds.size.width - 20)         let scale = newImageWidth/image.size.width         let newImageHeight = image.size.height * scale         attachment.bounds = CGRect.init(x: 0, y: 0, width: newImageWidth, height: newImageHeight)         //attributedString=NSTextAttachment()         let imageString = NSAttributedString(attachment: attachment)         // add this attributed string to the cusor position         noteTextView.textStorage.insert(imageString, at: noteTextView.selectedRange.location)         picker.dismiss(animated: true, completion: nil)     } The code working well. Now, how do I save it (with images) to DocumentsDirectory and how do I load it back? I can save/load without images. Thanks.
3
0
1.9k
May ’22
alertTextFieldDidChange(_:, for: .editingChanged)
I have an alertController, with one textField.. and alertAction button [Save]. When the textField presented (empty), the [Save].isEnabled = false. If user type anything in textField (none space), button [Save].isEnabled = true. code: field.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: .editingChanged) validation code: var alertController : UIAlertController? @objc func alertTextFieldDidChange(_ sender: UITextField) {    alertController?.actions[0].isEnabled = sender.text!.trimmingCharacters(in: .whitespacesAndNewlines).count > 0     } [Save] button works as expected. However, when I insert text in textField (as default entry): textField.text = "Test" textField showing "Text", if user choose to accept the default value "Test", [Save] button isEnabled will not change. User will have to type something in textField. I need some direction .. Thanks.
4
0
1k
May ’22