Swift之自定义UICollectionViewCell
来源:互联网 发布:c类网络借3位子网划分 编辑:程序博客网 时间:2024/05/18 11:47
自定义UICollectionViewCell和自定义UITableViewCell差不多,不过自定义UICollectionViewCell更像自定义UIView,具体代码如下
import UIKitclass ClassifyCollectionViewCell: UICollectionViewCell { var imageView: UIImageView! var titleLabel: UILabel! override init(frame:CGRect){ super.init(frame: frame) setupUI() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func setupUI(){ imageView = UIImageView() titleLabel = UILabel() titleLabel.font = UIFont.systemFont(ofSize: 13) titleLabel.textAlignment = .center titleLabel.textColor = UIColor.black self.addSubview(imageView) self.addSubview(titleLabel) self.backgroundColor = UIColor.white } override func layoutSubviews() { super.layoutSubviews() let frame:CGRect = self.bounds let imgx:CGFloat = 5.0 let imgy = imgx let frameWidth:CGFloat = frame.size.width let imgWidth:CGFloat = frameWidth - (imgx * 2.0) self.imageView.frame = CGRect(x: imgx, y: imgy, width: imgWidth, height: imgWidth) self.titleLabel.frame = CGRect(x: 0, y:imgy+frameWidth , width: frameWidth, height: 20) } override func awakeFromNib() { super.awakeFromNib() // Initialization code }}
阅读全文
0 0
- Swift之自定义UICollectionViewCell
- Swift自定义UICollectionViewCell不显示的解决方案
- UICollectionView学习<2>之UICollectionViewCell的自定义
- iOS 自定义UICollectionViewCell
- 自定义UICollectionViewCell控件调动BUG!
- Swift 使用SnapKit实现 UICollectionViewCell 高度自适应
- UICollectionViewCell
- UICollectionViewCell
- Swift之自定义SearchInput
- Swift之自定义UITableViewCell
- Swift之自定义UIView
- Swift之自定义UITableViewCell
- IOS自定义UICollectionViewCell(对比UITableViewCell)
- iOS UICollectionView 入门 05 创建自定义UICollectionViewCell
- IOS自定义UICollectionViewCell(对比UITableViewCell)
- 自定义UICollectionViewCell中控件为nil
- 自定义UICollectionViewCell 以及碰到的问题
- UICollectionView和自定义UICollectionViewCell的基本用法
- TortoiseSVN使用详细步骤
- CentOS7.3编译安装MariaDB10.2.6
- css3
- nuitka用法
- POJ 2247 Humble Numbers 笔记
- Swift之自定义UICollectionViewCell
- jquery
- WEBRTC 实时视频传输中的RTCP协议码率控制报文
- Android Studio中导出数据库文件的方法以及出现Failed to pull selection: open failed: Permission denied的解决思路
- bzoj1811: [Ioi2005]mea
- 最小费用最大流算法(SPFA邻接矩阵)
- 【题解】洛谷P2740 poj1273 [USACO4.2]草地排水Drainage Ditches
- 通用Excel导出Demo
- CentOS7.3编译安装Nginx1.10.1