最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果-創(chuàng)新互聯(lián)

這篇文章給大家介紹Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、通許網(wǎng)站維護(hù)、網(wǎng)站推廣。

創(chuàng)建一個(gè)類:PlayCollectionViewController.swift

//cell重用標(biāo)識(shí)private let reuseIdentifier = "reuseIdentifier"class PlayCollectionViewController: UICollectionViewController { //頁面?zhèn)€數(shù) private let pageCount = 6 //布局對(duì)象(自定義布局) private var layout: UICollectionViewFlowLayout = PlayLayout() init() {  super.init(collectionViewLayout: layout) } required init?(coder aDecoder: NSCoder) {  fatalError("init(coder:) has not been implemented") } override func viewDidLoad() {  super.viewDidLoad()  //注冊(cè)cell  collectionView?.registerClass(NewfearureCell.self, forCellWithReuseIdentifier: reuseIdentifier) } //MARK: - UICollectionDataSource override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {  return pageCount } override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {  let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! NewfearureCell  cell.imageIndex = indexPath.item  return cell }}

自定義CollectionView的cell

//MARK: - 在這里我們依然在(PlayCollectionViewController.swift的文件中)自定義collectionViewCellclass NewfearureCell: UICollectionViewCell { //保存圖片索引 private var imageIndex:Int? {  didSet {   //根據(jù)頁碼創(chuàng)建圖片名字(需要每張圖片的名稱只有最有最有一個(gè)數(shù)不同)   iconView.image = UIImage(named: "image_\(imageIndex!)")  } } override init(frame: CGRect) {  super.init(frame: frame)  //初始化UI  setupUI() } required init?(coder aDecoder: NSCoder) {  fatalError("init(coder:) has not been implemented") } private func setupUI() {  //添加子控件到contentView  contentView.addSubview(iconView)  //布局子控件位置(填充屏幕)  iconView.xmg_Fill(contentView) } //MARK: 懶加載 private lazy var iconView = UIImageView()}

繼承UICollectionViewFlowLayout,自定義布局

private class PlayLayout: UICollectionViewFlowLayout { //重寫系統(tǒng)準(zhǔn)備布局的方法 override func prepareLayout() {  //設(shè)置layout布局  itemSize = UIScreen.mainScreen().bounds.size  minimumInteritemSpacing = 0  minimumLineSpacing = 0  scrollDirection = UICollectionViewScrollDirection.Horizontal  //設(shè)置其他屬性  collectionView?.showsHorizontalScrollIndicator = false  collectionView?.bounces = false  collectionView?.pagingEnabled = true }}

關(guān)于Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。


當(dāng)前文章:Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果-創(chuàng)新互聯(lián)
鏈接URL:http://fisionsoft.com.cn/article/csehjh.html