如何在警报标题的右侧显示图像视图?

时间:2020-10-21 10:12:59

标签: ios swift alert

我想在警报视图标题旁边显示图像视图。为此,我添加了以下代码,但是我的问题是,警报标题和图像视图之间显示的空间太大。

    let attributedString = NSAttributedString(string: "Delete", attributes: [NSAttributedString.Key.foregroundColor : UIColor(named: "TextColor")!])

    let attributedMessageString = NSAttributedString(string: "Should the set heating time really be deleted?", attributes: [NSAttributedString.Key.foregroundColor : UIColor(named: "TextColor")!])

    let alert = UIAlertController(title: "", message: "",  preferredStyle: .alert)

    alert.setValue(attributedString, forKey: "attributedTitle")
    alert.setValue(attributedMessageString, forKey: "attributedMessage")

    alert.addAction(UIAlertAction(title: "Abort", style: .default, handler: nil))
    alert.addAction(UIAlertAction(title: "Delete", style: .default, handler: {(action:UIAlertAction!) in
        self.startTimeTextField.text = "--:--"
    }))
    
    let imgTitle = UIImage(named:"ArrowUpImage")
    let imgViewTitle = UIImageView(frame: CGRect(x: alert.view.center.x , y: 15, width: 30, height: 30))
    imgViewTitle.image = imgTitle

    alert.view.addSubview(imgViewTitle)

    let subview = (alert.view.subviews.first?.subviews.first?.subviews.first!)! as UIView
    subview.backgroundColor = UIColor(named: "BackgroundColor")
    alert.view.tintColor = UIColor(named: "SpecialColor")
    self.viewController.present(alert, animated: true, completion: nil)

我希望我的警报视图看起来像下面的图像(警报视图标题和图像视图之间的空间只有10个)。

enter image description here

你能帮我吗?

1 个答案:

答案 0 :(得分:1)

使用NSTextAttachment-

 let checkboxValue = xyz
 document.querySelectorAll("input[value="+checkboxValue+"]")[0].checked = false;
相关问题