Created
October 3, 2015 01:57
-
-
Save tempire/4e56e6a4a0ff7e589e6e to your computer and use it in GitHub Desktop.
UIView NSBundle Storyboard
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
import Foundation | |
import UIKit | |
class CustomerDetailProgressVC: UIViewController { | |
@IBOutlet weak var scrollView: UIScrollView! | |
@IBOutlet weak var progressListView: UIView! | |
let rightItemPadding: CGFloat = 10 | |
let itemHeight: CGFloat = 60 | |
var model: Model? | |
var customer: Customer? | |
var timeline = [ | |
(title: "Payment Collected", field: "paymentCollectedDate"), | |
(title: "Site Survey Approved", field: "siteSurveyApprovedDate"), | |
(title: "Site Survey Appointment", field: "siteSurveyAppointmentDate"), | |
(title: "Site Survey Completed", field: "siteSurveyAppointmentDate") | |
] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
customizeAppearance() | |
} | |
override func viewWillAppear(animated: Bool) { | |
super.viewWillAppear(animated) | |
setNavigationTitle("Progress") | |
} | |
func customizeAppearance() { | |
view.backgroundColor = UIColor.viewBackgroundColor() | |
var previousListItem = addProgressListItem("createdDate", title: "Lead Entered", atRelationAttribute: .Top, ofRelationItem: progressListView) | |
var passedToday = false | |
for point in timeline { | |
let date = customer?.valueForKey(point.field) as? NSDate | |
if !passedToday && (date == nil || date >= NSDate()) { | |
previousListItem = addTodayListItemAt(.Bottom, ofRelationItem: previousListItem) | |
passedToday = true | |
} | |
previousListItem = addProgressListItem(point.field, title: point.title, atRelationAttribute: .Bottom, ofRelationItem: previousListItem) | |
} | |
view.setNeedsLayout() | |
} | |
func addProgressListItem(name: String, title: String, atRelationAttribute relationAttribute: NSLayoutAttribute, ofRelationItem relationItem: UIView) -> UIView { | |
let item = ProgressItem() | |
let dateValue = customer?.valueForKey(name) as? NSDate | |
item.dateLabel.text = dateValue?.toString(dateStyle: NSDateFormatterStyle.MediumStyle, timeStyle: NSDateFormatterStyle.NoStyle) ?? "Pending" | |
item.circleView.backgroundColor = dateValue == nil ? UIColor.yellowColor() : UIColor.greenColor() | |
item.stepLabel.text = title | |
item.statusLabel.text = dateValue == nil ? "Pending" : "Completed" | |
progressListView.addSubview(item) | |
let top = NSLayoutConstraint(item: item, attribute: .Top, relatedBy: .Equal, toItem: relationItem, attribute: relationAttribute, multiplier: 1, constant: 0) | |
let left = NSLayoutConstraint(item: item, attribute: .Left, relatedBy: .Equal, toItem: progressListView, attribute: .Left, multiplier: 1, constant: 0) | |
let right = NSLayoutConstraint(item: item, attribute: .Right, relatedBy: .Equal, toItem: progressListView, attribute: .Right, multiplier: 1, constant: -rightItemPadding) | |
progressListView.addConstraints([top, left, right]) | |
let height = NSLayoutConstraint(item: item, attribute: .Height, relatedBy: .Equal, toItem: .None, attribute: .NotAnAttribute, multiplier: 1, constant: itemHeight) | |
item.addConstraints([height]) | |
return item | |
} | |
func addTodayListItemAt(relationAttribute: NSLayoutAttribute, ofRelationItem relationItem: UIView) -> UIView { | |
let item = TodayProgressItem() | |
item.dateLabel.text = NSDate().toString(dateStyle: NSDateFormatterStyle.MediumStyle, timeStyle: NSDateFormatterStyle.NoStyle) ?? "Pending" | |
item.todayLabel.text = "Today" | |
progressListView.addSubview(item) | |
let top = NSLayoutConstraint(item: item, attribute: .Top, relatedBy: .Equal, toItem: relationItem, attribute: relationAttribute, multiplier: 1, constant: 0) | |
let left = NSLayoutConstraint(item: item, attribute: .Left, relatedBy: .Equal, toItem: progressListView, attribute: .Left, multiplier: 1, constant: 0) | |
let right = NSLayoutConstraint(item: item, attribute: .Right, relatedBy: .Equal, toItem: progressListView, attribute: .Right, multiplier: 1, constant: -rightItemPadding) | |
progressListView.addConstraints([top, left, right]) | |
let height = NSLayoutConstraint(item: item, attribute: .Height, relatedBy: .Equal, toItem: .None, attribute: .NotAnAttribute, multiplier: 1, constant: itemHeight) | |
item.addConstraints([height]) | |
return item | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment