swift 商品排序

来源:互联网 发布:网络诽谤案例 编辑:程序博客网 时间:2024/05/22 04:56
////  collectionShopViewCell.swift//  JadeWorld////  Created by 行走的牧马人 on 2016/12/27.//  Copyright © 2016年 XJW. All rights reserved.//import UIKitclass collectionShopViewCell: UICollectionViewCell {    var commodityImageView : UIImageView!        var typeImageView : UIImageView!        var priceLabel : UILabel!        var contentLabel : UILabel!        var detailsLabel : UILabel!        var authorLabel :UILabel!        var authorImageView :UIImageView!        override init(frame: CGRect) {        super.init(frame: frame)        let kwidth = self.frame.size.width        let kheight = self.frame.size.height        self.backgroundColor = UIColor.whiteColor()                commodityImageView = UIImageView()        commodityImageView.translatesAutoresizingMaskIntoConstraints = false        self.contentView.addSubview(commodityImageView)        commodityImageView.snp_makeConstraints { (make) in            make.top.equalTo(0)            make.left.equalTo(0)            make.width.equalTo(kwidth)            make.height.equalTo(kheight/1.7)        }                typeImageView = UIImageView()        typeImageView.translatesAutoresizingMaskIntoConstraints = false        self.contentView.addSubview(typeImageView)        typeImageView.snp_makeConstraints { (make) in            make.top.equalTo(0)            make.left.equalTo(0)            make.width.equalTo(30)            make.height.equalTo(30)        }                authorImageView = UIImageView()        authorImageView.translatesAutoresizingMaskIntoConstraints = false        self.contentView.addSubview(authorImageView)        authorImageView.snp_makeConstraints { (make) in            make.top.equalTo(commodityImageView.snp_bottom).offset(5)            make.left.equalTo(5)            make.width.equalTo(kwidth/3.5)            make.height.equalTo(kwidth/3.5)        }                priceLabel = UILabel()                priceLabel.translatesAutoresizingMaskIntoConstraints = false                priceLabel.textColor = UIColor(red: 173/255, green: 0/255, blue: 0/255, alpha: 1)                priceLabel.textAlignment = .Center                priceLabel.font = UIFont.systemFontOfSize(kwidth/9)                self.contentView.addSubview(priceLabel)                priceLabel.snp_makeConstraints { (make) in            make.top.equalTo(commodityImageView.snp_bottom).offset(0)            make.left.equalTo(authorImageView.snp_right).offset(5)            make.right.equalTo(0)            make.height.equalTo(kheight/10)        }                        contentLabel = UILabel()                contentLabel.translatesAutoresizingMaskIntoConstraints = false                contentLabel.textColor = UIColor.blackColor()                contentLabel.textAlignment = .Center                contentLabel.font = UIFont.systemFontOfSize(kwidth/10)                self.contentView.addSubview(contentLabel)                contentLabel.snp_makeConstraints { (make) in            make.top.equalTo(priceLabel.snp_bottom).offset(0)            make.left.equalTo(authorImageView.snp_right).offset(5)            make.right.equalTo(0)            make.height.equalTo(kheight/10)        }                authorLabel = UILabel()                authorLabel.translatesAutoresizingMaskIntoConstraints = false                authorLabel.textAlignment = .Left                authorLabel.font = UIFont.systemFontOfSize(kwidth/9)                self.contentView.addSubview(authorLabel)                authorLabel.snp_makeConstraints { (make) in            make.height.equalTo(kheight/8)            make.left.equalTo(5)            make.width.equalTo(kwidth-10)            make.top.equalTo(contentLabel.snp_bottom).offset(5)        }                        detailsLabel = UILabel()                detailsLabel.translatesAutoresizingMaskIntoConstraints = false                detailsLabel.text = "查看详细"                detailsLabel.textColor = UIColor.whiteColor()                detailsLabel.backgroundColor = UIColor(red: 60/255, green: 58/255, blue: 58/255, alpha: 1)                detailsLabel.textAlignment = .Center                detailsLabel.font = UIFont.systemFontOfSize(kwidth/11)                self.contentView.addSubview(detailsLabel)                detailsLabel.snp_makeConstraints { (make) in            make.bottom.equalTo(0)            make.left.equalTo(0)            make.width.equalTo(kwidth)            make.top.equalTo(authorLabel.snp_bottom).offset(0)        }            }        required init?(coder aDecoder: NSCoder) {        fatalError("init(coder:) has not been implemented")    }}
////  collecTionViewController.swift//  JadeWorld////  Created by 行走的牧马人 on 2016/12/27.//  Copyright © 2016年 XJW. All rights reserved.//import UIKitclass collecTionViewController: BaseViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {        var collectionView : UICollectionView!        var testAryImage = ["test1","test2","test3","test4","test6","test6","test7","test8"]        var testAryPrice = ["188888","388888","299999","1999","600000","780000","999999","5999","270000"]        var testAryImage2 = ["镶嵌名家12_03_01","镶嵌名家12_03_02","镶嵌名家12_03_03","镶嵌名家12_03_04","镶嵌名家12_03_05","镶嵌名家12_03_06","镶嵌名家12_03_07","镶嵌名家12_03_08","镶嵌名家12_03_09"]        var testAryName = ["新疆和田玉","岫玉","独山玉","绿松石","缅甸翡翠","石英质玉石","硅质交代玉石","青金石","祖母绿"]        var testAryTypeImage = ["雕刻原料_1","雕刻原料_2","雕刻原料_3","雕刻原料_4","雕刻原料_5","雕刻原料_6","雕刻原料_7","雕刻原料_8","雕刻原料_9","雕刻原料_10","雕刻原料_11","雕刻原料_12"]        var testAryName2 = ["施宗颖","段华竹","吴秋强","张青兰","苏杭越","杨政","鸿鹄裕","吴清华","林国"]        var testView : ScreeningMeunView!        override func viewDidLoad() {        super.viewDidLoad()        self.view.backgroundColor = UIColor(red: 34/255, green: 23/255, blue: 22/255, alpha: 1)                let btnView = UIView()        btnView.frame=CGRectMake(0, 70, kWidth, 40)        btnView.backgroundColor = UIColor(red: 239/255, green: 239/255, blue: 239/255, alpha: 1)        self.view.addSubview(btnView)                let customButton = CustomButton()        customButton.frame=CGRectMake(kWidth-kWidth/7,0, kWidth/5, 40)        customButton.addTarget(self, action:#selector(tapped), forControlEvents:.TouchUpInside)        btnView.addSubview(customButton)                createCollectionView()            }    func tapped(button:UIButton){        testView = ScreeningMeunView(frame: CGRectMake(kWidth,0,kWidth-kWidth/5,kHeight))        self.view.addSubview(testView)                UIView.animateWithDuration(0.4, animations: {            self.testView.frame = CGRectMake(kWidth-(kWidth-(kWidth/5)), 0, kWidth-kWidth/5,kHeight)        }) { (isOver:Bool) in            print("动画结束")        }    }    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {        UIView.animateWithDuration(0.4, animations: {            self.testView.frame = CGRectMake(kWidth, 0, kWidth-kWidth/5,kHeight)        }) { (isOver:Bool) in            self.testView.removeFromSuperview()            print("removeFromSuperview")        }    }        //创建网格视图    func createCollectionView(){        //布局对象        let flowLayout=UICollectionViewFlowLayout()        flowLayout.sectionInset=UIEdgeInsetsMake(10, 10, 10,10)        flowLayout.itemSize=CGSizeMake(kWidth/3.5, kHeight/3.8)        flowLayout.minimumInteritemSpacing=5;        flowLayout.minimumLineSpacing=20;                let frame=CGRectMake(0, 110, kWidth, kHeight-150)                let collectionView=UICollectionView(frame: frame, collectionViewLayout: flowLayout)        collectionView.backgroundColor = UIColor.clearColor()        collectionView.delegate=self        collectionView.dataSource=self                self.view.addSubview(collectionView)        //注册cell        collectionView.registerClass(collectionShopViewCell.classForCoder(), forCellWithReuseIdentifier: "Cell")            }    //item数    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {                return testAryTypeImage.count    }    //组数    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {        return 1    }    //cell    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! collectionShopViewCell                let temp1 = Int(arc4random()%8)                cell.commodityImageView.image = UIImage(named:testAryImage[temp1])                let temp2 = Int(arc4random()%12)        cell.typeImageView.image = UIImage(named: testAryTypeImage[temp2]);                let temp3 = Int(arc4random()%9)                cell.authorImageView.image = UIImage(named:testAryImage2[temp3])                cell.priceLabel.text = "¥"+testAryPrice[temp3]+"元"                cell.contentLabel.text = testAryName[temp3]                cell.authorLabel.text = "作者: " + testAryName2[temp3]                        return cell    }        override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()            }        }


0 0
原创粉丝点击