【问题标题】:How display a custom view on the storyboard?如何在故事板上显示自定义视图?
【发布时间】:2018-09-19 13:50:15
【问题描述】:

我创建了一个自定义视图,但是当我将它添加到情节提要屏幕时,它不显示内容(启动应用程序时,所有内容都会显示)。 在看到lesson 之后,我意识到我需要在类前面添加“IBDesignable”,但这并没有帮助,我在 View 中看不到内容。而且,现在Xcode会报渲染错误:

"IB Designables: Failed to render and update auto layout status for Test1ViewController (R7h-8I-M68): The agent threw an exception.".

请教你的意见

import UIKit

@IBDesignable class ww: UIView {

    var view: UIView!

    @IBOutlet weak var yellowLine: UIView!

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.commonInit()
    }

    func commonInit()
    {
        let view = Bundle.main.loadNibNamed("ww", owner: self, options: nil)?.first as! UIView
        view.frame = self.bounds
        view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.addSubview(view)
    }

  }

附: - 我无法添加图片,因为我的声誉

【问题讨论】:

标签: swift view xib


【解决方案1】:
    let refundViewVC = self.storyboard?.instantiateViewController(withIdentifier: "refundViewController") as! refundViewController

    refundViewVC.delegate = self
    refundViewVC.modalPresentationStyle = .overCurrentContext
    refundViewVC.modalTransitionStyle = .crossDissolve
    refundViewVC.definesPresentationContext = true
    refundViewVC.view.backgroundColor = UIColor.init(red: 74/255, green: 74/255, blue: 74/255, alpha: 0.5)

    self.navigationController?.present(refundViewVC, animated: true, completion: nil)

“refundViewController”是我的 UIViewController 类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-06
    • 2013-08-04
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2011-12-01
    相关资源
    最近更新 更多