欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果

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

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

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

//cell重用標(biāo)識(shí)private let reuseIdentifier = "reuseIdentifier"class PlayCollectionViewController: UICollectionViewController { //頁(yè)面?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ù)頁(yè)碼創(chuàng)建圖片名字(需要每張圖片的名稱(chē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 { //重寫(xiě)系統(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í)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

名稱(chēng)欄目:Swift中怎么使用CollectionView實(shí)現(xiàn)廣告欄滑動(dòng)效果
轉(zhuǎn)載來(lái)于:http://www.chinadenli.net/article32/peigpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站微信公眾號(hào)動(dòng)態(tài)網(wǎng)站網(wǎng)站設(shè)計(jì)網(wǎng)站導(dǎo)航虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站