// // RenameViewController.swift // MusicPlayer // // Created by Mr.Zhou on 2024/4/7. // import UIKit class MPSideA_RenameViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var textField: UITextField!{ didSet{ textField.attributedPlaceholder = NSAttributedString(string: "Placeholder", attributes: [NSAttributedString.Key.foregroundColor:UIColor.init(hex: "#EBEBF5"), NSAttributedString.Key.font : UIFont.systemFont(ofSize: 13, weight: .regular)]) textField.delegate = self } } var renameBlock:((String) -> Void)? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let text = (textField.text! as NSString).replacingCharacters(in: range, with: string) guard text.count <= 60 else { return false } return true } @IBAction func confirmClick(_ sender: UIButton) { guard let text = textField.text, text != "" else { return } dismiss(animated: true) { [weak self] in if self?.renameBlock != nil { self?.renameBlock!(text) } } } @IBAction func cancelClick(_ sender: UIButton) { dismiss(animated: true) } }