//
// 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: 用代码创建
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- http://blog.csdn.net/syg90178aw/article/details/46981277
- 要求是图片为正方形,图片下面是标题和其它的内容,我这里图片和文字都写给的固定的值做完后的效果是这样的: 流布局UI...