YLCycleView
Swift無限輪播
如何使用?
Demo運行會報錯。請你務必對demo進行 pod install
YLCycleView文件夾拖入你的項目
let images = ["http://c.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01f50d40bbee5fe9925bd317d8c.jpg", "1", "2", "3", "4"]
let titles = ["Raindew","無限輪播", "QQ群:511860085", "歡迎加入", "帥的人已經Star"]
let cycleView = YLCycleView(frame: CGRect(x: 0, y: 100, width: self.view.bounds.width, height: 150), images: images, titles: titles)
view.addSubview(cycleView)
你可以在把本地圖片名稱直接放進數組里,也可以放一個URL
為了方便網絡圖片,我做了這樣一個處理,但是同時我需要麻煩你在項目中引入Kingfisher 這個三方
如果你想獲取點擊事件請設置代理并且遵守它!最后實現代理方法。如果你不需要,忽略它。
cycleView.delegate = self;
func clickedCycleView(_ cycleView : YLCycleView, selectedIndex index: Int) {
print("點擊了第\(index)頁")
}
大多數而言,這個滾動視圖都是有一個title的。當然如果你不需要直接這樣創建視圖:
let cycleView = YLCycleView(frame: CGRect(x: 0, y: 100, width: self.view.bounds.width, height: 150), images: images)
想要更新數據?
// MARK: -- reload
func reload() {
cycleView.titles = []//可以為空。可以為nil-->此時隱藏標題
cycleView.images = ["1", "2", "3"]//不要為空,否則沒圖片了
//請務必刷新!
cycleView.reloadData()
}
重要提醒:如果你使用了導航,那么你必須在使用控制器中設置滾動偏移,復制下面一行代碼到你的控制器中
self.automaticallyAdjustsScrollViewInsets = false
效果圖
image
YLMenuView
如何使用?
//類方法創建
let menuView = YLMenuView.ylMenuView()
menuView.frame = CGRect(x: 10, y: 320, width: self.view.bounds.width - 20, height: 250)
menuView.delegate = self
//你可以給一個URL也可以給一個本地圖片
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: ["這是一條重大新聞","吃貨節到了錢包準備好了嗎","獨家福利來就送!"], tagSource: ["新聞", "吃貨節", "福利"])
singlerView.delegate = self
//更多公開屬性自行查找
// singlerView.backColor = .darkGray
// singlerView.contentTextColor = .purple
// singlerView.tagBackgroundColors = [.white,.yellow,.cyan]
// singlerView.tagTextColors = [.red,.blue,.black]
view.addSubview(singlerView)
重要提醒:如果你使用了導航,那么你必須在使用控制器中設置滾動偏移,復制下面一行代碼到你的控制器中
self.automaticallyAdjustsScrollViewInsets = false
點擊跳轉代理
//MARK: -- YLSinglerViewDelegate
func singlerView(_ singlerowView: YLSinglerowView, selectedIndex index: Int) {
print("點擊了第\(index)個數據")
}
效果scrollStyle: .up(上下左右皆可滾動)
image
如果scrollStyle: .left
image
如果你希望設置更多屬性,例如字體背景顏色等。打開上面代碼注釋
image
項目下載地址
iOS技術交流群:511860085 歡迎加入!