Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created June 29, 2015 11:04
Show Gist options
  • Save MickaelCruzDB/9d0150d966f213e80848 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/9d0150d966f213e80848 to your computer and use it in GitHub Desktop.
import UIKit
class ProductCell: UICollectionViewCell {
// The collection view cell's objects
var imageView: UIImageView!
var caption: UILabel!
var category : UILabel!
var bu : UILabel!
override func preferredLayoutAttributesFittingAttributes(layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes! {
return layoutAttributes
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
// Create an ImageView and add it to the collection view
imageView = UIImageView(frame: CGRect(x:30, y:12, width:65, height:65))
imageView.contentMode = UIViewContentMode.ScaleAspectFill
contentView.addSubview(imageView)
// Create a Label view and add it to the collection view
let textFrame = CGRect(x:12, y:67, width:100, height:55)
caption = UILabel(frame: textFrame)
caption.font = UIFont.systemFontOfSize(14.0)
caption.textAlignment = .Center
caption.numberOfLines = 2
caption.lineBreakMode = NSLineBreakMode.ByWordWrapping
caption.textColor = UIColor.whiteColor()
caption.backgroundColor = UIColor.clearColor()
contentView.addSubview(caption)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment