Skip to content

Instantly share code, notes, and snippets.

@ebbnormal
Created July 25, 2016 21:25
Show Gist options
  • Save ebbnormal/edb79a15dab4797946e0d1f6905c2dd0 to your computer and use it in GitHub Desktop.
Save ebbnormal/edb79a15dab4797946e0d1f6905c2dd0 to your computer and use it in GitHub Desktop.
class ChronicleCell :UICollectionViewCell {
var CoverURLBase = "URLURL"
var chronicle: BrowsableChronicle? {
didSet {
if let name = chronicle?.coverTitle {
let attributedText = NSMutableAttributedString(string: name, attributes: [NSFontAttributeName: UIFont.boldSystemFontOfSize(30)])
nameLabel.textColor = UIColor.blackColor()
nameLabel.attributedText = attributedText
coverImage.kf_setImageWithURL(NSURL(string: (self.CoverURLBase + chronicle!.coverPicID!))!)
//set specific coordinates of each pointbutton view
//monkey.frame = CGRect(x: bananax, y: bananay, width: monkey.frame.size.width, height: monkey.frame.size.height)
//iterate through however many points there are
//print("point list on chron is \(chronicle?)")
//TODO checking out the chron
if let chron = chronicle{
print(chron)
if let pointList = chron.pointList{
print(pointList)
}
}
if let pointList = chronicle?.pointList {
let origin_x = self.frame.midX
let origin_y = self.frame.midY
print("width of frame is \(self.frame.width)")
let list = pointList
let size = list.count
for index in 0...(size-1){
if (index == 0){
let point = list[0]
point1.frame = CGRect(x: Int(origin_x) + point.axisX!, y: Int(origin_y) + point.axisY!, width:25, height:25)
if let title = point1view.subviews[0] as? UILabel{
title.text = point.pointTitle
}
if let summary = point1view.subviews[1] as? UILabel{
summary.text = point.summary
}
print("setting point1 frame ")
}
if (index == 1){
let point = list[1]
point2.frame = CGRect(x: Int(origin_x) + point.axisX! , y: Int(origin_y) + point.axisY!, width:25, height:25)
if let title = point2view.subviews[0] as? UILabel{
title.text = point.pointTitle
}
if let summary = point2view.subviews[1] as? UILabel{
summary.text = point.summary
}
}
if (index == 2){
let point = list[2]
point3.frame = CGRect(x: Int(origin_x) + point.axisX!, y: Int(origin_y) + point.axisY!, width:25, height:25)
if let title = point3view.subviews[0] as? UILabel{
title.text = point.pointTitle
}
if let summary = point3view.subviews[1] as? UILabel{
summary.text = point.summary
}
}
if (index == 3){
let point = list[3]
if let title = point4view.subviews[0] as? UILabel{
title.text = point.pointTitle
}
if let summary = point4view.subviews[1] as? UILabel{
summary.text = point.summary
}
point4.frame = CGRect(x: Int(origin_x) + point.axisX! , y: Int(origin_y) + point.axisY!, width:25, height:25)
}
}
}
//set handlers of clicking each point to open up the right popover?
point1.addTarget(self, action: #selector(chronicleOneClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
point2.addTarget(self, action: #selector(chronicleTwoClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
point3.addTarget(self, action: #selector(chronicleThreeClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
point4.addTarget(self, action: #selector(chronicleFourClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
}
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let nameLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 2
return label
}()
let coverImage: UIImageView = {
//TODO it looks like i create an image view everytime. we should see if it is defined, already?
//print("creating a new image view")
let imageView = UIImageView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, (UIScreen.mainScreen().bounds.width * 0.6) ))
imageView.contentMode = .ScaleAspectFit
imageView.layer.masksToBounds = true
return imageView
}()
let point1 : PointButtonView = {
let pointView = PointButtonView(frame: CGRectMake(0, 0, 25, 25 ))
return pointView
}()
let point2 : PointButtonView = {
let pointView = PointButtonView(frame: CGRectMake(0, 0, 25, 25 ))
return pointView
}()
let point3 : PointButtonView = {
let pointView = PointButtonView(frame: CGRectMake(0, 0, 25, 25 ))
return pointView
}()
let point4 : PointButtonView = {
let pointView = PointButtonView(frame: CGRectMake(0, 0, 25, 25 ))
return pointView
}()
let point1view : UIView = {
//to access this in future
//point1view.subviews[0] is title
//point1view.subviews[1] is summary
//you need to cast the subviews as UILabels
let pointView = UIView(frame: CGRectMake(0, 0, 200, 270))
let title = UILabel(frame: CGRectMake(0, 0, 200, 21))
pointView.addSubview(title)
let summary = UILabel(frame: CGRectMake(0, 20, 200, 260))
pointView.addSubview(summary)
pointView.tag = 100
pointView.backgroundColor = UIColor.whiteColor()
return pointView
}()
let point2view : UIView = {
let pointView = UIView(frame: CGRectMake(0, 0, 100, 130))
let title = UILabel()
pointView.addSubview(title)
let summary = UILabel()
pointView.addSubview(summary)
pointView.tag = 200
return pointView
}()
let point3view : UIView = {
let pointView = UIView(frame: CGRectMake(0, 0, 100, 130))
let title = UILabel()
pointView.addSubview(title)
let summary = UILabel()
pointView.addSubview(summary)
pointView.tag = 300
return pointView
}()
let point4view : UIView = {
let pointView = UIView(frame: CGRectMake(0, 0, 100, 130))
let title = UILabel()
pointView.addSubview(title)
let summary = UILabel()
pointView.addSubview(summary)
pointView.tag = 400
return pointView
}()
func chronicleOneClicked(sender: UIButton){
//addsubview to this view
//set point1view.subviews to add to self
point1view.backgroundColor = UIColor.whiteColor()
addSubview(point1view)
//addConstraintsWithFormat("|-50-[v0]-50-|", views: point1view)
}
func chronicleTwoClicked(sender: UIButton){
addSubview(point2view)
print("adding point 2 subview")
}
func chronicleThreeClicked(sender: UIButton){
addSubview(point3view)
print("adding point 3 subview")
}
func chronicleFourClicked(sender: UIButton){
addSubview(point4view)
print("adding point 4 subview")
}
func setupViews() {
addSubview(coverImage)
addSubview(nameLabel)
addSubview(point1)
addSubview(point2)
addSubview(point3)
addSubview(point4)
//vertical contraint 20 units above top of superview
//TODO
addConstraintsWithFormat("V:|-20-[v0]|", views: nameLabel)
//addConstraintsWithFormat("H:|[v0]|", views: point1view)
//addConstraintsWithFormat("H:[v0]", views: coverImage)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment