//
// 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: 用代码创建
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- http://blog.csdn.net/syg90178aw/article/details/46981277
- 要求是图片为正方形,图片下面是标题和其它的内容,我这里图片和文字都写给的固定的值做完后的效果是这样的: 流布局UI...