macOS 13.2 UITextField misalignment when tapped

The test field was originally centered. However, as I tap on it, it was brought to the left. This UI issue occurs on macOS 13.2, built on My Mac(Designed for iPad), while running on iPad is totally fine. Xcode 14.2 and 14.1 has the same behaviour.

import UIKit

class ViewController: UIViewController {
    
    let textField: UITextField = {
        let textField = UITextField()
        textField.translatesAutoresizingMaskIntoConstraints = false
        textField.backgroundColor = .green
        textField.textAlignment = .center
        textField.text = "Hello, World"
        return textField
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(textField)
        
        NSLayoutConstraint.activate([
            textField.widthAnchor.constraint(equalToConstant: 200),
            textField.heightAnchor.constraint(equalToConstant: 50),
            textField.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            textField.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
        
    }
}

How can I fix this?

This is a bug. I reported it on another thread - using SwiftUI. The good news is that this seem to be fixed in 13.3 beta 2.

@limtc Thanks for indicating it will be fixed in 13.3.

Well, I tested my code (in SwiftUI) and in current macOS beta it is indeed fixed. You might want to try on latest beta.

Unfortunately in beta 3 the issue is back. :(

It is fixed in 13.4. Just tested and it works!

macOS 13.2 UITextField misalignment when tapped
 
 
Q