Cell: 用代码创建

//
//  LimitCell.swift
//  loveLimitedFree
//
//  Created by 邓江洲 on 16/8/4.
//  Copyright © 2016年 邓江洲. All rights reserved.
//

import UIKit

class LimitCell: UITableViewCell {
    
    
    var backgroundImageView: UIImageView?
    var iconImageView: UIImageView?
    var nameLabel: UILabel?
    
    var timeLabel: UILabel?
    var originalPriceLabel: UILabel?
    var starView: StarView? //MARK:- hehe
    
    var categoryLabel: UILabel?
    var shareLabel: UILabel?
    var favouriteLabel: UILabel?
    
    var downloadLabel: UILabel?
    
    
    
    
    
    
    
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        
        
        
        self.backgroundImageView = UIImageView(frame: CGRectMake(0, 0, 375, 100))
        self.contentView.addSubview(self.backgroundImageView!)
        self.iconImageView = UIImageView(frame: CGRectMake(20, 10, 60, 60))
        self.contentView.addSubview(self.iconImageView!)
        self.nameLabel = UILabel(frame: CGRectMake(100,4,200,20))
        self.contentView.addSubview(self.nameLabel!)
        
        
        
        self.timeLabel = UILabel(frame: CGRectMake(100,28,150,20))
        self.contentView.addSubview(self.timeLabel!)
        self.originalPriceLabel = UILabel(frame: CGRectMake(260,28,100,20))
        self.contentView.addSubview(self.originalPriceLabel!)
        self.starView = StarView(frame: CGRectMake(100, 50, 65, 23))
        self.contentView.addSubview(self.starView!)
        
        
        
        self.categoryLabel = UILabel(frame: CGRectMake(240,52,100,20))
        self.contentView.addSubview(self.categoryLabel!)
        self.categoryLabel?.layer.borderColor = UIColor.cyanColor().CGColor
        self.categoryLabel?.layer.borderWidth = 2
        self.categoryLabel?.textAlignment = .Center
        
        
        
        self.shareLabel = UILabel(frame: CGRectMake(20,76,100,20))
        self.contentView.addSubview(self.shareLabel!)
        self.favouriteLabel = UILabel(frame: CGRectMake(130,76,100,20))
        self.contentView.addSubview(self.favouriteLabel!)
        
        
        
        self.downloadLabel = UILabel(frame: CGRectMake(240,76,100,20))
        self.contentView.addSubview(self.downloadLabel!)
        
        
        
    }
    
    
    
    
    
    func configurationMessageByModel(model: LimitModel, atIndex index: Int, deleteToTheLength cutTimeIndex: Int){
    
        
        
        if index%3 == 1 {
            self.backgroundImageView?.image = UIImage(named: "cate_list_bg1")
        }else if index%3 == 2{
            self.backgroundImageView?.image = UIImage(named: "cate_list_bg2")
        }else {
            self.backgroundImageView?.image = nil            
        }
        
        
        
        let iconUrl = NSURL(string: model.iconUrl!)
        self.iconImageView?.kf_setImageWithURL(iconUrl)
        
        
        self.nameLabel?.text = "\(index+1). \(model.name!)"
        self.categoryLabel?.text = Util.transferCateName(model.categoryName!)
        
        
        
        
        let priceString = "¥: \(model.lastPrice!)"
        let priceAttributedString = NSAttributedString(string: priceString, attributes: [NSStrikethroughStyleAttributeName: 2, NSStrikethroughColorAttributeName: UIColor.redColor()])
        self.originalPriceLabel?.attributedText = priceAttributedString
        
        
        let rate = NSString(string: model.starCurrent!).floatValue
        self.starView?.setStars(CGFloat(rate))
        
        
      
        
        
        let timeTextIndex = model.expireDatetime?.endIndex.advancedBy(-cutTimeIndex)
        let timeString = model.expireDatetime?.substringToIndex(timeTextIndex!)
        let dateFormat = NSDateFormatter()
        //2016-08-05 00:58:35.0
        dateFormat.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let expireTime = dateFormat.dateFromString(timeString!)//很明显的 正则表达式)
        let carlendar = NSCalendar.currentCalendar()
        let unitFlags = NSCalendarUnit(rawValue: NSCalendarUnit.Hour.rawValue | NSCalendarUnit.Minute.rawValue | NSCalendarUnit.Second.rawValue )
        let dateTimeNeeds = carlendar.components(unitFlags, fromDate: NSDate(), toDate: expireTime!, options: NSCalendarOptions(rawValue: 0) )
        self.timeLabel?.text = String(format: "剩余 %2d: %02d: %02d .", dateTimeNeeds.hour, dateTimeNeeds.minute, dateTimeNeeds.second)
        
        
    
        self.shareLabel?.text = "分享 \(model.shares!)次"
        self.favouriteLabel?.text = "收藏 \(model.favorites!)次"
        self.downloadLabel?.text = "下载 \(model.downloads!)次"
        
    }   
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}


你可能感兴趣的:(Cell: 用代码创建)