如何以编程方式在任何视图(UICollectionViewController,UITableViewController,UIViewController)中插入UIView?

时间:2017-05-18 21:02:56

标签: ios swift uiview uiviewcontroller

我创建了一个像这样的UIView:

class miniPlayerBar: UIView {

    lazy var miniPlayerButton: UIButton = {
        let button = UIButton(type: .system)
        button.backgroundColor = .orange
        button.setTitle("Open", for: .normal)
        button.setTitleColor(.white, for: .normal)
        button.addTarget(self, action: #selector(presentFullPlayer), for: .touchUpInside)
        button.layer.cornerRadius = 5
        return button
    }()

    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
        addSubview(self.miniPlayerButton)

        _ = miniPlayerButton.anchor(nil, left: leftAnchor, bottom: bottomAnchor, right: rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 49, rightConstant: 0, widthConstant: 0, heightConstant: 26)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func presentFullPlayer() {

    }

我希望能够在视图控制器上显示此视图。如何在任何视图控制器(tableview,collectionview,UIViewController)中显示它?

0 个答案:

没有答案