8 C
Canberra
Friday, July 25, 2025

ios – UITextField wherein methodology I can observe combining two symbols in to at least one?


I do not suppose there is a particular methodology in your case however you may observe it manually:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    non-public let textField: UITextField = {
        let textual content = UITextField()
        textField.borderStyle = .roundedRect
        textField.translatesAutoresizingMaskIntoConstraints = false
        return tf
    }()
    
    non-public var previousText: String = ""

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        view.backgroundColor = .white
        setupTextField()
    }

    non-public func setupTextField() {
        view.addSubview(textField)
        textField.delegate = self
        textField.addTarget(self, motion: #selector(textFieldDidChange(_:)), for: .editingChanged)

        NSLayoutConstraint.activate([
            textField.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            textField.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            textField.widthAnchor.constraint(equalToConstant: 250),
            textField.heightAnchor.constraint(equalToConstant: 40)
        ])
    }

    @objc non-public func textFieldDidChange(_ textField: UITextField) {
        guard let newText = textField.textual content else { return }
        
        if hasCombinedCharacters(earlier: previousText, present: newText) {
            print("Обнаружено объединение символов!")
        }
        
        previousText = newText
    }

    non-public func hasCombinedCharacters(earlier: String, present: String) -> Bool {
        let prevDecomposed = earlier.decomposedStringWithCanonicalMapping
        let currDecomposed = present.decomposedStringWithCanonicalMapping
        
        return prevDecomposed.rely == currDecomposed.rely
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles