Swift 無(wú)限輪播

YLCycleView

Swift無(wú)限輪播

如何使用?

Demo運(yùn)行會(huì)報(bào)錯(cuò)。請(qǐng)你務(wù)必對(duì)demo進(jìn)行 pod install

YLCycleView文件夾拖入你的項(xiàng)目

      let images = ["http://c.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01f50d40bbee5fe9925bd317d8c.jpg", "1", "2", "3", "4"]
      let titles = ["Raindew","無(wú)限輪播", "QQ群:511860085", "歡迎加入", "帥的人已經(jīng)Star"]
      let cycleView = YLCycleView(frame: CGRect(x: 0, y: 100, width: self.view.bounds.width, height: 150), images: images, titles: titles)
      view.addSubview(cycleView)

你可以在把本地圖片名稱直接放進(jìn)數(shù)組里,也可以放一個(gè)URL
為了方便網(wǎng)絡(luò)圖片,我做了這樣一個(gè)處理,但是同時(shí)我需要麻煩你在項(xiàng)目中引入Kingfisher 這個(gè)三方

如果你想獲取點(diǎn)擊事件請(qǐng)?jiān)O(shè)置代理并且遵守它!最后實(shí)現(xiàn)代理方法。如果你不需要,忽略它。

   cycleView.delegate = self;
   func  clickedCycleView(_ cycleView : YLCycleView, selectedIndex index: Int) {
      print("點(diǎn)擊了第\(index)頁(yè)")
  }

大多數(shù)而言,這個(gè)滾動(dòng)視圖都是有一個(gè)title的。當(dāng)然如果你不需要直接這樣創(chuàng)建視圖:

      let cycleView = YLCycleView(frame: CGRect(x: 0, y: 100, width: self.view.bounds.width, height: 150), images: images)

想要更新數(shù)據(jù)?

  // MARK: -- reload
    func reload() {
        cycleView.titles = []//可以為空??梢詾閚il-->此時(shí)隱藏標(biāo)題
        cycleView.images = ["1", "2", "3"]//不要為空,否則沒(méi)圖片了
        //請(qǐng)務(wù)必刷新!
        cycleView.reloadData()
    }

重要提醒:如果你使用了導(dǎo)航,那么你必須在使用控制器中設(shè)置滾動(dòng)偏移,復(fù)制下面一行代碼到你的控制器中

 self.automaticallyAdjustsScrollViewInsets = false

效果圖

image

YLMenuView

如何使用?


//類方法創(chuàng)建
      let menuView = YLMenuView.ylMenuView()
      menuView.frame = CGRect(x: 10, y: 320, width: self.view.bounds.width - 20, height: 250)
      menuView.delegate = self
      //你可以給一個(gè)URL也可以給一個(gè)本地圖片
      menuView.imageArray = ["http://tx.haiqq.com/uploads/allimg/150322/021422Lb-10.jpg",
                             "http://img.wzfzl.cn/uploads/allimg/150522/co150522214536-15.jpg",
                             "http://img.wzfzl.cn/uploads/allimg/150119/co150119220K2-18.jpg",
                             "http://uploads.xuexila.com/allimg/1608/704-160Q5100Z6.jpg",
                             "http://tx.haiqq.com/uploads/allimg/150326/1P4511163-9.jpg",
                             "http://tx.haiqq.com/uploads/allimg/150323/15135032M-1.jpg",
                             "http://img.wzfzl.cn/uploads/allimg/150522/co150522214536-15.jpg",
                             "http://img.wzfzl.cn/uploads/allimg/150119/co150119220K2-18.jpg",
                             "http://uploads.xuexila.com/allimg/1608/704-160Q5100Z6.jpg",
                             "http://tx.haiqq.com/uploads/allimg/150326/1P4511163-9.jpg",
                             "http://tx.haiqq.com/uploads/allimg/150323/15135032M-1.jpg",
                             "http://tx.haiqq.com/uploads/allimg/150323/15135032M-1.jpg",
                             "1"
      ]
      menuView.titleArray = ["http", "2345", "345", "uploads", "2345", "allimg", "34545", "uploads", "345", "http", "uploads", "uploads", "uploads"]
      //                menuView.itemsOfPage = 6
      //        menuView.imageViewSize = CGSize(width: 60, height: 60)
      //        menuView.pageControl.pageIndicatorTintColor = .white
      //        menuView.pageControl.currentPageIndicatorTintColor = .darkGray
      view.addSubview(menuView)

MenuView.gif

YLSinglerowView

如何使用?


      let singlerView = YLSinglerowView(frame: CGRect(x: 50, y: 350, width: 200, height: 30), scrollStyle: .up, roundTime: 5, contentSource: ["這是一條重大新聞","吃貨節(jié)到了錢包準(zhǔn)備好了嗎","獨(dú)家福利來(lái)就送!"], tagSource: ["新聞", "吃貨節(jié)", "福利"])
      singlerView.delegate = self
      //更多公開屬性自行查找
      //        singlerView.backColor = .darkGray
      //        singlerView.contentTextColor = .purple
      //        singlerView.tagBackgroundColors = [.white,.yellow,.cyan]
      //        singlerView.tagTextColors = [.red,.blue,.black]

      view.addSubview(singlerView)

重要提醒:如果你使用了導(dǎo)航,那么你必須在使用控制器中設(shè)置滾動(dòng)偏移,復(fù)制下面一行代碼到你的控制器中

 self.automaticallyAdjustsScrollViewInsets = false

點(diǎn)擊跳轉(zhuǎn)代理

    //MARK: -- YLSinglerViewDelegate
    func singlerView(_ singlerowView: YLSinglerowView, selectedIndex index: Int) {
        print("點(diǎn)擊了第\(index)個(gè)數(shù)據(jù)")
    }

效果scrollStyle: .up(上下左右皆可滾動(dòng))

image

如果scrollStyle: .left

image

如果你希望設(shè)置更多屬性,例如字體背景顏色等。打開上面代碼注釋

image

項(xiàng)目下載地址
iOS技術(shù)交流群:511860085 歡迎加入!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,161評(píng)論 4 61
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,534評(píng)論 19 139
  • 輪播圖和無(wú)限自動(dòng)輪播圖實(shí)現(xiàn)起來(lái)都非常簡(jiǎn)單,實(shí)現(xiàn)效果如下: 主要實(shí)現(xiàn)功能分頁(yè),定時(shí)切換,滑動(dòng)到最后一頁(yè)之后自動(dòng)滑動(dòng)到...
    FlyElephant閱讀 396評(píng)論 0 2
  • <前言> 我出生在湘南邊陲的一個(gè)普通的小村莊。 那里依山傍水,后山綿延的松林和村前一大片稻田使這個(gè)小小的村莊看上去...
    夢(mèng)中de安娜閱讀 677評(píng)論 3 6
  • JavaScript的數(shù)組是JavaScript原生的唯一的復(fù)雜數(shù)據(jù)結(jié)構(gòu),這點(diǎn)有點(diǎn)類似于php。(JSON是一種輕...
    一口咖啡一口茶閱讀 444評(píng)論 3 3

友情鏈接更多精彩內(nèi)容