验证中...
本周日【珠海源创会】一起聊聊:PingCAP分布式事务、支付宝移动端实践、GSBN技术框架选型,点此报名占座
语言: Swift
分类: iOS 组件
最后更新于 2018-10-22 15:36
autosize.swift
原始数据 复制代码
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label: UIButton!
override func loadView() {
super.loadView()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let square = UIButton(type: .system)
square.translatesAutoresizingMaskIntoConstraints = false
square.setTitle("asdgj", for: .normal)
view.addSubview(square)
self.view.addConstraints([
//NSLayoutConstraint(item: square, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 1),
//NSLayoutConstraint(item: square, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: square, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: square, attribute: .centerY, relatedBy: .equal, toItem: self.view, attribute: .centerY, multiplier: 1.0, constant: 0),
])
square.backgroundColor = UIColor.yellow
let fixedSize = square.frame.size.width
square.sizeThatFits(CGSize(width: fixedSize, height: CGFloat.greatestFiniteMagnitude))
}
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助

12_float_left_people 12_float_left_close