Last active
August 29, 2015 14:28
-
-
Save cactis/bea4a0207e9f987051cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TaskCell.swift | |
// imuc | |
// | |
// Created by ctslin on 2015/8/13. | |
// Copyright (c) 2015年 ctslin. All rights reserved. | |
// | |
import UIKit | |
class TaskCell: UITableViewCell { | |
var data: Task! | |
var row1, row2, row3: UIView! | |
var action, subject, due_date: UILabel! | |
var status: UIButton! | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
} | |
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
setupUI() | |
} | |
func setupUI(){ | |
row1 = contentView.addView() | |
row2 = contentView.addView() | |
row3 = contentView.addView() | |
action = row1.addLabel(LoremIpsum.sentence(), options: ["fontSize": 20]) | |
subject = row2.addLabel(LoremIpsum.sentence(), options: ["fontSize": 14]) | |
due_date = row2.addLabel("", options: ["fontSize": 12]) | |
status = row3.addButton("", options: ["fontSize": 12, "color": UIColor.whiteColor()]) | |
} | |
func styleUI() { | |
due_date.textAlignment = .Right | |
// status.titleLabel?.textAlignment = .Right | |
if status.titleLabel!.text != nil { | |
if status.titleLabel!.text == "Finished" { | |
status.backgroundColor = UIColor.greenColor().darker().darker() | |
} else { | |
status.backgroundColor = UIColor.redColor().lighter() | |
} | |
} | |
status.layer.cornerRadius = 2 | |
status.clipsToBounds = true | |
status.contentEdgeInsets = UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5) | |
} | |
override func setSelected(selected: Bool, animated: Bool) { | |
super.setSelected(selected, animated: animated) | |
} | |
override func updateConstraints() { | |
super.updateConstraints() | |
// println(__FUNCTION__) | |
row1.alignToTop() | |
row2.isBelowTo(row1, options: ["offset": 0]) | |
row3.isBelowTo(row2, options: ["offset": 5]) | |
action.alignToLeading() | |
subject.alignToLeading() | |
due_date.isRightOf(subject) | |
due_date.autoSetDimension(.Width, toSize: 120) | |
due_date.autoPinEdgeToSuperviewMargin(.Trailing) | |
status.alignToTrailing() | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment