ios - Swift - 带有图像的 UIAlertController

标签 ios iphone swift

我有这个代码:

let alert = UIAlertController(title:"title", preferredStyle: UIAlertControllerStyle.alert)
    let saveAction = UIAlertAction(title: "Title", style: .default, handler: nil)

    var imageView = UIImageView(frame: CGRectMake(10, 10, 250, 124))
    imageView.image = zdjecieGlowne
    alert.view.addSubview(imageView)

    alert.addAction(UIAlertAction(title: "Button 1", style: UIAlertActionStyle.default, handler: { alertAction in
        print("1 pressed")
    }))
    alert.addAction(UIAlertAction(title: "Button 2", style: UIAlertActionStyle.cancel, handler: { alertAction in
        print("2 pressed")
    }))
    alert.addAction(UIAlertAction(title: "Button 3", style: UIAlertActionStyle.default, handler: { alertAction in
        print("3 pressed")
    }))
    self.present(alert, animated: true, completion: nil)
}

窗口看起来像这样: https://ibb.co/hM5zHH

图片上覆盖着我的按钮。有谁知道如何解决吗?

最佳答案

试试这个,它可能对你有帮助

    let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
    let action = UIAlertAction(title: "OK", style: .cancel, handler: nil)

    //Add imageview to alert
    let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
    imgViewTitle.image = UIImage(named:"image.png")
    alert.view.addSubview(imgViewTitle)

    alert.addAction(action)
    self.present(alert, animated: true, completion: nil)

关于ios - Swift - 带有图像的 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49791851/

相关文章:

iphone - iOS Storyboard 模态序列和内存

ios - 如何转义正则表达式字符串

objective-c - 分配和释放问题

ios - 根据标签文本的大小创建具有动态高度的 UILabel

ios - 与 Deinit 和内存泄漏混淆

iphone - UILocalNotification 在模拟器中播放声音但在设备上不播放

ios - NSHTTPCookieStorage 丢失 cookie,如果应用程序在重启后手机至少解锁一次之前启动

ios - 使用 NSPredicate 搜索字符串数组的数组

ios - Swift/如何填充 UITableViewCells

ios - 虚拟内存中的 UIImage 表示