I'm trying to bring a label into front, but with no luck:
class UITextFieldCustom : UITextField, UITextFieldDelegate {
public var valueSuccess = true;
public var textValue = "";
public var keyboardToolBar : UIToolbar!;
public var helpLabel: UILabel = UILabel();
// MARK: - init
init(frame: CGRect, size: CGFloat) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.layer.borderColor = UIColor.gray.cgColor
let f = self.bounds;
helpLabel.frame = CGRect(x: f.origin.x - 20, y: f.origin.y - 10, width: 75, height: 30);
helpLabel.backgroundColor = UIColor.systemBlue;
helpLabel.textColor = UIColor.white;
helpLabel.layer.borderColor = UIColor.red.cgColor;
helpLabel.layer.borderWidth = 0.5;
helpLabel.layer.masksToBounds = true;
helpLabel.layer.cornerRadius = 3;
helpLabel.layer.zPosition = 1;
helpLabel.isHidden = true;
helpLabel.setMargins(10);
self.addSubview(helpLabel);
}
If the label isHidden is set to false, the label appears, but not in frontmost position:
I've tried with:
helpLabel.layer.zPosition = 1;
self.bringSubviewToFront(helpLabel);
UIApplication.shared.keyWindow!.bringSubviewToFront(helpLabel)