专栏名称: 程序员大咖
为程序员提供最优质的博文、最精彩的讨论、最实用的开发资源;提供最新最全的编程学习资料:PHP、Objective-C、Java、Swift、C/C++函数库、.NET Framework类库、J2SE API等等。并不定期奉送各种福利。
目录
相关文章推荐
京东零售技术  ·  前沿论文分享 | ... ·  2 天前  
京东科技技术说  ·  【银河麒麟高级服务器操作系统】正式上线云主机 ... ·  3 天前  
腾讯技术工程  ·  0day漏洞量产?AI Agent“生产线”曝光 ·  2 天前  
51好读  ›  专栏  ›  程序员大咖

iOS layoutMargins 的坑:一个活久见的 bug

程序员大咖  · 公众号  · 程序员  · 2018-03-27 09:00

正文

请到「今天看啥」查看全文



super.init(frame: frame)


imageView.backgroundColor = UIColor.red

metadataView.backgroundColor = UIColor.green


for view in [imageView, metadataView] {

addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false

view.leadingAnchor.constraint(equalTo: self.layoutMarginsGuide.leadingAnchor).isActive = true

view.trailingAnchor.constraint(equalTo: self.layoutMarginsGuide.trailingAnchor).isActive = true

}


imageView.topAnchor.constraint(equalTo: self.layoutMarginsGuide.topAnchor).isActive = true

imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true


metadataView.topAnchor.constraint(equalTo: imageView.bottomAnchor).isActive = true

metadataView.heightAnchor.constraint(equalToConstant: 25).isActive = true

metadataView.bottomAnchor.constraint(equalTo: self.layoutMarginsGuide.bottomAnchor).isActive = true

}


required public init?(coder aDecoder: NSCoder) {

fatalError("init(coder:) has not been implemented")

}

}


final class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {


override func viewDidLoad() {

super.viewDidLoad()


self.collectionView!.contentInsetAdjustmentBehavior = .never

self.collectionView!.register(TestCell.self, forCellWithReuseIdentifier: "Cell")

}


// MARK: UICollectionViewDataSource


override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return 10

}


override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {







请到「今天看啥」查看全文