gpt4 book ai didi

ios - 在 SDCAlertView 中添加约束

转载 作者:可可西里 更新时间:2023-11-01 02:17:16 28 4
gpt4 key购买 nike

我正在使用 pod SDCAlertView,我需要向我的内容 View 添加一个 imageView + 一个 textField,但是我在约束方面遇到了问题,下面是我的代码。

let imageView = UIImageView(frame: CGRectMake(0, 0, 100, 100))
imageView.image = UIImage(named: "kalafina")
imageView.contentMode = .ScaleAspectFill
let alert = AlertController(title: "Testing", message: "1234")
imageView.translatesAutoresizingMaskIntoConstraints = false
alert.contentView.addSubview(imageView)


let imageHeightConstraint = NSLayoutConstraint(item: imageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 100)
let imageWidthConstraint = NSLayoutConstraint(item: imageView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 100)
let imageCenterXConstraint = NSLayoutConstraint(item: imageView, attribute: .CenterX, relatedBy: .Equal, toItem: alert.contentView, attribute: .CenterX, multiplier: 1.0, constant: 0.0)
let imageTopConstraint = NSLayoutConstraint(item: imageView, attribute: .Top, relatedBy: .Equal, toItem: alert.contentView, attribute: .Top, multiplier: 1.0, constant: 0)
let imageBottomConstraint = NSLayoutConstraint(item: imageView, attribute: .Bottom, relatedBy: .Equal, toItem: alert.contentView, attribute: .Bottom, multiplier: 1.0, constant: 0)
alert.view.addConstraint(imageTopConstraint)
alert.view.addConstraint(imageBottomConstraint)
alert.view.addConstraint(imageHeightConstraint)
alert.view.addConstraint(imageWidthConstraint)
alert.view.addConstraint(imageCenterXConstraint)

alert.addAction(AlertAction(title: "Cancel", style: .Preferred))
alert.addAction(AlertAction(title: "Ok", style: .Default, handler: { action in

print("Sending")

}))
alert.present()

这是我的结果enter image description here

最佳答案

您正在将约束添加到 alert.view,但您应该将它们添加到 alert.contentView。如果您这样做,一切都会按预期进行。

关于ios - 在 SDCAlertView 中添加约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36275358/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com