ios swift banner轮播图

我们要封装一个无限轮播图 也可以直接去GitHub上下载封装完的第三方地址:https://github.com/GitHubCFer01/BannerView

打开连接下载第三方 导入工程,工程自动添加了oc桥梁
在桥梁的类里导入头文件

#import "BannerView.h"

我们可以把轮播图写进表格,这样方便往下写分组表格

class uiViewController: UIViewController ,UITableViewDataSource ,UITableViewDelegate {
    
   var array:NSMutableArray!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        array = NSMutableArray.init(array: ["1","2"])
        let tableV = UITableView.init(frame: self.view.frame)
        tableV.delegate = self
        tableV.dataSource = self
        
        self.view.addSubview(tableV)
        
        tableV.register(UINib.init(nibName: "MyTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
        tableV.register(BannerTableViewCell.classForCoder(), forCellReuseIdentifier: "banner")
        tableV.register(UINib.init(nibName: "QvKuaiTableViewCell", bundle: nil), forCellReuseIdentifier: "quKuai")
        tableV.register(UINib.init(nibName: "ImageTableViewCell", bundle: nil), forCellReuseIdentifier: "image")
        tableV.register(UINib.init(nibName: "DccTableViewCell", bundle: nil), forCellReuseIdentifier: "dcc")
        
        print(array)
        
        // Do any additional setup after loading the view.
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        
        return 5
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        if section == 0 || section == 1 || section == 3 || section == 4{
            
            return 1
        }else{
            
            return 3
        }
        
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.section == 0 {
            
            let cell = tableView.dequeueReusableCell(withIdentifier: "banner")
            
            return cell!
        }else if indexPath.section == 1{
            
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
            
            return cell!
        }else if indexPath.section == 2{
            
            let cell = tableView.dequeueReusableCell(withIdentifier: "quKuai")
            
            return cell!
        }else if indexPath.section == 3{
            let cell = tableView.dequeueReusableCell(withIdentifier: "image")
            
            return cell!
        }else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "dcc")
            
            return cell!
        }
        
        return UITableViewCell()
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 300
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        if indexPath.section == 0 {
            
            return 300
        }else{
            
            return 80;
        }
    }

    

创建分组的cell
在xib里面拖拽你需要的控件

创建继承于TableViewCell的类

func bannerV() -> Void {
        
        let array = NSMutableArray.init(array: ["1","2"])
        let banner = BannerView(frame: CGRect.init(x: 0, y: 0, width: self.contentView.bounds.size.width, height: 300), addImageArray: array)
        
        self.contentView.addSubview(banner!)
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: UITableViewCellStyle.subtitle, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor.red
        self.bannerV()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

重写父类方法

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,105评论 3 119
  • 昨天,你的悄然无息离去 不管是欢愉、浮华 还是忧郁、悲伤 我真的不在乎 虽然我珍惜你 我真正在乎的是我的明天 如何...
    公马水手阅读 1,580评论 0 0
  • 黑夜的微风, 吹扶我的身体, 此时的南方, 深夜未睡的你! 五月的太阳, 照射我的身体, 微燥的心里, 同处五月的...
    行道子阅读 1,666评论 0 2
  • 夜 静静的躺下 光线慢慢退出了帐幔 云霞逐渐隐没在远山 洁净的窗台在悄悄等待 等待月光到来 来了 风 萧索着 摇曳...
    孟尤阅读 2,515评论 0 0
  • 除了荷花,向日鲜艳的黄色让人特别有力量。原图是用马克笔,颜色更为好看。
    花如许阅读 2,920评论 0 1

友情链接更多精彩内容