微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于Swift与EasyIOS的UICollectionView演示代码

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

//
//  ViewController.swift
//  easySwift
//
//  Created by zhuchao on 14-7-15.
//  copyright (c) 2014 year zhuchao. All rights reserved.
//

import UIKit

class AwesomeScene: Scene {
                            
    @IBOutlet strong var collectionView: SceneCollectionView!
    var dict:NSDictionary!
    var showFont:String!
    override func viewDidLoad() {
        super.viewDidLoad()
        showFont = fontAwesome
        
        self.collectionView.registerClass(IconCell.classForCoder(),forCellWithReuseIdentifier: "IconCell")
        self.collectionView.backgroundColor = UIColor(string: "#E9E9E9");
        var fontDict:NSDictionary = NSDictionary.objectFromData(NSData.fromresource("fontIconConfig.json")) as NSDictionary
        var json:Nsstring = fontDict.objectForKey(showFont).objectForKey("json") as Nsstring
        dict = NSDictionary.objectFromData(NSData.fromresource(json)) as NSDictionary
        self.collectionView.dataArray = NSMutableArray(array: dict.allKeys)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // dispose of any resources that can be recreated.
    }

    func collectionView(collectionView: UICollectionView!,numberOfItemsInSection section: Int) -> Int{
        return self.collectionView.dataArray.count
    }
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int{
        return 1
    }
    
    func collectionView(collectionView: UICollectionView!,cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!{
        var cell:IconCell = collectionView.dequeueReusableCellWithReuseIdentifier("IconCell",forIndexPath: indexPath) as IconCell
        var key = self.collectionView.dataArray.objectAtIndex(indexPath.row) as String
        var icon = dict.objectForKey(key) as String
        IconFont.label(cell.iconMainView,fontName: showFont,setIcon: icon,size: 50.0,color: UIColor.blackColor(),sizetoFit:true)
        return cell
    }
    
    func collectionView(collectionView: UICollectionView!,layout collectionViewLayout: UICollectionViewLayout!,sizeforItemAtIndexPath indexPath: NSIndexPath!) -> CGSize{
        return CGSizeMake(50,65)
    }
    
    func collectionView(collectionView: UICollectionView!,insetForSectionAtIndex section: Int) -> UIEdgeInsets{
        return UIEdgeInsetsMake(10,10,10);
    }
    
    func collectionView(collectionView: UICollectionView!,didSelectItemAtIndexPath indexPath: NSIndexPath!){
        var key = self.collectionView.dataArray.objectAtIndex(indexPath.row) as String
        DialogUtil.showDlgalert(key)
    }
}

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐