ios: no se puede establecer el color del texto de UILabel implementado como vista personalizada para UIBarButtonItem

CorePress2024-01-25  9

Me gustaría implementar una etiqueta personalizada en la barra de herramientas, pero no puedo cambiar el color del texto:

 // MARK: - Initialize the status label (toolbar)
    func initStatusLabel() {
        statusLabel.layer.borderColor = UIColor.red.cgColor;
        statusLabel.layer.borderWidth = 1;
        statusLabel.layer.masksToBounds = true;
        statusLabel.layer.cornerRadius = 8;
        statusLabel.font = statusLabel.font.withSize(12);
        statusLabel.leftTextInset = 8;
        statusLabel.rightTextInset = 8;
        statusLabel.topTextInset = 8;
        statusLabel.bottomTextInset = 8;
        statusLabel.text = "Hello World";
        statusLabel.adjustsFontSizeToFitWidth = true;
        statusLabel.backgroundColor = .systemRed;
        statusLabel.textColor = .white;
        statusLabel.sizeToFit();
    }

El color blanco se ignorará por algunos motivos:

¿Alguna idea?



------------------------------------

Intenta configurar el color de tinte para UILable, o también puedes usar UIButton

let rightBarButtonItem = UIBarButtonItem(title: "Some text", style: .plain, target: self, action: #selector(someAction))

rightBarButtonItem.tintColor = UIColor.myMusicPurple 



------------------------------------

Encontré la razón. Obviamente no puedes cambiar el color si el elemento del botón de la barra no está habilitado en el storyboa.rd:

Su guía para un futuro mejor - libreflare
Su guía para un futuro mejor - libreflare