Together项目IOS平台开发06

时至端午,已经是第六次代码的提交。由于之前的搜索界面仍然在研究,这次先暂时放一边。这次要更新的界面是主页的设计以及实现,也就是推荐栏。推荐栏是用户在进入我的应用之后第一个看到的页面。在这个页面中我将会给用户呈现出平台推荐的众筹项目。主要的内容包括一个推荐的轮播栏,还有轮播栏下方的其他项目。总体来说,我使用了一个tableview作为整个界面的整体框架。我将轮播设置为tableview的头视图,轮播栏会呈现推荐的图片,按一定时间进行自动循环播放。轮播是一个所有应用都会常使用的插件,这个功能的代码在网上就能找到相当详细的模版。轮播栏的视线中使用了ImageHelper的第三方库,用以简化图片的显示。

整个页面布局还未嵌入实际的项目内容,具体的页面如下


具体推荐栏代码如下

import UIKit

class RecommendViewController: UIViewController,SliderGalleryControllerDelegate,UITableViewDelegate,UITableViewDataSource {

    let screenSizeWidth = UIScreen.main.bounds.size.width
    
    let screenSizeHeight = UIScreen.main.bounds.size.height

    //图片轮播组件
    var sliderGallery : SliderGalleryController!
    
    var tableview0 : UITableView?
    
    var dataArray:[String]!
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        dataArray = [String]()
        for i in 1 ..< 10
        {
            dataArray.append("第\(i)行")
        }
        
        self.view.backgroundColor = UIColor.white
        
        tableview0 = UITableView(frame:CGRect(x:0,y:0,width:screenSizeWidth,height:screenSizeHeight),style:.plain)
        
        self.view.addSubview(tableview0!)
        
        tableview0?.rowHeight = UITableViewAutomaticDimension
        
        tableview0?.dataSource = self
        
        tableview0?.delegate = self
        
        //初始化图片轮播组件
        sliderGallery = SliderGalleryController()
        
        sliderGallery.delegate = self
        
        sliderGallery.view.frame = CGRect(x: 0, y: 70, width: screenSizeWidth,
                                          height: (screenSizeWidth-100)/4*3);
        
        //将图片轮播组件添加到当前视图
        self.addChildViewController(sliderGallery)
        
        tableview0?.tableHeaderView = sliderGallery.view
        //添加组件的点击事件
        let tap = UITapGestureRecognizer(target: self,action: #selector(RecommendViewController.handleTapAction(_:)))
        
        sliderGallery.view.addGestureRecognizer(tap)

    }
    //图片轮播组件协议方法:获取内部scrollView尺寸
    func galleryScrollerViewSize() -> CGSize {
        return CGSize(width: screenSizeWidth, height:(screenSizeWidth-100)/4*3)
    }
    
    //图片轮播组件协议方法:获取数据集合
    func galleryDataSource() -> [String] {
        return ["https://imgsa.baidu.com/forum/w%3D580/sign=f25c7f7be324b899de3c79305e071d59/ab1dfa09b3de9c820b3cacf46681800a19d84331.jpg",
            "https://imgsa.baidu.com/forum/w%3D580%3B/sign=21b7ebf3b8119313c743ffb855030dd7/e61190ef76c6a7efbcef8d17f7faaf51f3de6631.jpg",
        "https://img30.360buyimg.com/cf/jfs/t5311/292/2421593131/548229/a5da55a5/591aa5daN34ee9c6c.jpg"]
    }
    
    //点击事件响应
    func handleTapAction(_ tap:UITapGestureRecognizer)->Void{
        //获取图片索引值
        let index = sliderGallery.currentIndex
        
        //弹出索引信息
        let alertController = UIAlertController(title: "您点击的图片索引是:",message: "\(index)", preferredStyle: .alert)
        
        let cancelAction = UIAlertAction(title: "确定", style: .cancel, handler: nil)
        
        alertController.addAction(cancelAction)
        
        self.present(alertController, animated: true, completion: nil)
    }
    
//    //设置每一行的内容
//    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//        
//        let identify:String = "SwiftCell"
//        
//        var cell = tableView.dequeueReusableCell(withIdentifier: identify, for: indexPath as IndexPath)
//        
//        cell.textLabel?.text=dataArray![indexPath.row]
//        return cell
//    }
//    
//    //设置需要展示的行数
//    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        return dataArray.count  
//    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
       
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataArray.count
    }
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
       
        return 100
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = UITableViewCell()
        
        cell.detailTextLabel?.text = "gaga"

        cell.textLabel?.text=dataArray![indexPath.row]
        
        switch indexPath.row {
        default:
            let image3 = UIImage(named:"button_log02")
            
            cell.imageView?.image = image3
        }

        
        return cell
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值