【问题标题】:How to add a UITableview inside a UIImageview programmatically in Swift 3如何在 Swift 3 中以编程方式在 UIImageview 中添加 UITableview
【发布时间】:2018-07-21 05:34:13
【问题描述】:

如何在 Swift 3 中以编程方式在 UIImageview 中添加 UITableview,我已尝试使用 Xcode 默认 UIImageview 和 UITableview,但我的应用程序崩溃了。

【问题讨论】:

  • 您应该添加更多详细信息和您尝试过的一些代码,请参阅stackoverflow.com/help/how-to-ask,因为您的问题几乎没有意义
  • 可以把tableview放在imageview上面,不能在imageview中addSubview。
  • 你遇到了什么问题,所以你尝试过的代码,最终显示一些 UI 你期望什么类型的 OP
  • 我的要求是我想在 UIImageview 中加载一个 uitableview ,如果不可能,我应该使用 uiview 代替 UIimageview 吗?

标签: ios iphone swift


【解决方案1】:

您不能在 UIImageView 中添加 UITableView。 您可以获取一个 UIView 并在此视图中添加 UIImageView 和 UITableView。

let bgView = UIView.init(frame: self.view.frame)   //Frame of the view
    let imageView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: bgView.frame.width, height: bgView.frame.height))   
        imageView.image = #imageLiteral(resourceName: "imgDefault")
    let tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: bgView.frame.width, height: bgView.frame.height))
        tableView.backgroundColor = UIColor.clear
    bgView.addSubview(imageView)
    bgView.addSubview(tableView)
    self.view.addSubview(bgView)

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多