123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // MineServiceTableViewCell.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/4/24.
- // Copyright © 2019 南鑫林. All rights reserved.
- //
- import UIKit
- class MineServiceTableViewCell: UITableViewCell {
-
- let titles = ["客服电话","个人资料","账号安全"]
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> MineServiceTableViewCell {
- let ID = "MineServiceTableViewCell"
- tableView.register(MineServiceTableViewCell.self, forCellReuseIdentifier: ID)
- let cell : MineServiceTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! MineServiceTableViewCell
- cell.indexPath = indexPath
- return cell
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- setupLayouts()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- var indexPath: IndexPath? {
- didSet {
-
- }
- }
- //MRAK: - 设置View
- private func setupViews() {
- self.selectionStyle = .none
- backgroundColor = kf7f8faColor
- addSubview(bgView)
- bgView.addSubview(topButton)
- topButton.addSubview(titleLabel)
- topButton.addSubview(lineLabel)
- bgView.addSubview(collectionView)
- }
-
- private func setupLayouts() {
- bgView.snp.makeConstraints { (make) in
- make.top.bottom.equalToSuperview()
- make.left.equalTo(14)
- make.right.equalTo(-14)
- }
-
- topButton.snp.makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.height.equalTo(44)
- }
- titleLabel.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.left.equalTo(10)
- }
- lineLabel.snp.makeConstraints { (make) in
- make.left.right.bottom.equalToSuperview()
- make.height.equalTo(0.5)
- }
- collectionView.snp.makeConstraints { (make) in
- make.top.equalTo(topButton.snp.bottom)
- make.left.equalTo(0)
- make.right.equalTo(0)
- make.height.equalTo(kScaleValue(value: 94))
- make.bottom.lessThanOrEqualTo(bgView)
- }
- }
-
- private lazy var bgView: UIView = {
- let bgView = UIView()
- bgView.backgroundColor = UIColor.white
- bgView.cornerRadius = 2.5
- bgView.masksToBounds = true
- return bgView
- }()
-
- private lazy var topButton: UIButton = {
- let topButton = UIButton(type: UIButton.ButtonType.custom)
- return topButton
- }()
-
- private lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.text = "我的服务"
- titleLabel.textColor = k333333Color
- titleLabel.font = kMediumFont16
- return titleLabel
- }()
-
- private lazy var lineLabel: UILabel = {
- let lineLabel = UILabel()
- lineLabel.backgroundColor = kf5f5f5Color
- return lineLabel
- }()
-
- private lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = UIColor.white
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.cornerRadius = 2.5
- collectionView.masksToBounds = true
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 0
- collectionViewLayout.minimumInteritemSpacing = 0
- return collectionViewLayout
- }()
-
- //加载数据
- func reloadData() {
-
- //collectionView重新加载数据
- self.collectionView.reloadData()
- //更新collectionView的高度约束
- let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
- collectionView.snp.remakeConstraints { (make) in
- make.top.equalTo(topButton.snp.bottom)
- make.left.right.equalToSuperview()
- make.height.equalTo(contentSize.height)
- make.bottom.lessThanOrEqualTo(bgView)
- }
-
- self.collectionView.collectionViewLayout.invalidateLayout()
- }
-
- }
- extension MineServiceTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return titles.count
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = MineServiceCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.titles = titles
- return cell
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- showSwiftProgressHUDInfo()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:kScreenWidth-28, height: 48)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
- }
-
- }
|