我的代码是:
let alert = UIAlertController(title: "title", message: "alert", preferredStyle: UIAlertControllerStyle.Alert)
let image_view = UIImageView(frame: CGRectMake(70, 10, 200, 200))
image_view.image = UIImage(named: "logo")
alert.view.addSubview(image_view)
alert.addTextFieldWithConfigurationHandler { textField in textField.placeholder = "a textfield"
alert.addTextFieldWithConfigurationHandler { textField in textField.placeholder = "another textfield" }
然而,这导致我的徽标与UITextFields重叠。我怎样才能确保它们整齐地堆叠在一起?
答案 0 :(得分:0)
从我的角度来看,如果您想使用自定义用户界面创建UIAlertController
,请尝试通过自己创建。或者,如果你想使用这样一个hacky解决方案:
let image = UIImage(named: "logo")
alert.setValue(image, forKey: "image")
答案 1 :(得分:0)
尝试将框架设置为文本字段: -
var textField = UITextField()
textField.frame = CGRect(x: , y: image_view.bounds.minY + 10, width: 250, height: 40)
textField.placeholder = "a textfield"
alertController.view.addSubview(textField)
设置框架对我有用。
答案 2 :(得分:0)
您需要设计自定义警报控制器example
因为UIAlertController
功能有限
@available(iOS 8.0, *)
open class UIAlertController : UIViewController {
public convenience init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle)
open func addAction(_ action: UIAlertAction)
open var actions: [UIAlertAction] { get }
@available(iOS 9.0, *)
open var preferredAction: UIAlertAction?
open func addTextField(configurationHandler: ((UITextField) -> Swift.Void)? = nil)
open var textFields: [UITextField]? { get }
open var title: String?
open var message: String?
open var preferredStyle: UIAlertControllerStyle { get }
}