美文网首页
swift VFL 简单使用

swift VFL 简单使用

作者: 蚂蚁也疯狂 | 来源:发表于2018-06-17 09:55 被阅读15次
    xcode 9 swfit4.1
    // 属性传值
    let attributeBtn = UIButton.init()
    attributeBtn.translatesAutoresizingMaskIntoConstraints = false
    attributeBtn.setTitle("属性传值", for: .normal)
    attributeBtn.setTitleColor(UIColor.black, for: .normal)
    self.view.addSubview(attributeBtn)
    attributeBtn.addTarget(self, action: #selector(RootViewController.attributeBtnClicked), for: .touchUpInside)
    
    attributeBtn.layer.borderColor = UIColor.green.cgColor
     attributeBtn.layer.borderWidth = 3.0
    
    // layout Views
    let layoutViews:[String:AnyObject] = ["attributeBtn": attributeBtn]
    //创建水平方向约束
    self.view.addConstraints(NSLayoutConstraint.constraints(
                withVisualFormat: "H:|-5-[attributeBtn]-5-|", options:.alignAllCenterX,
                metrics: nil, views: layoutViews))
    //创建垂直方向约束
    self.view.addConstraints(NSLayoutConstraint.constraints(
                withVisualFormat: "V:|-64-[attributeBtn(==50)]|",
                options:NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: layoutViews))
    

    相关文章

      网友评论

          本文标题:swift VFL 简单使用

          本文链接:https://www.haomeiwen.com/subject/esnieftx.html