Skip to content

Instantly share code, notes, and snippets.

@lborgav
Forked from Katafalkas/gist:eb5e840df1ace981c359
Last active August 28, 2015 07:11
Show Gist options
  • Save lborgav/aad8b94c65a819c167fe to your computer and use it in GitHub Desktop.
Save lborgav/aad8b94c65a819c167fe to your computer and use it in GitHub Desktop.
Swift UITableViewCell custom subclass simple Chat Bubble
class Cell: UITableViewCell {
override func drawRect(rect: CGRect) {
var bubbleSpace = CGRectMake(20.0, self.bounds.origin.y, self.bounds.width - 20, self.bounds.height)
let bubblePath1 = UIBezierPath(roundedRect: bubbleSpace, byRoundingCorners: .TopLeft | .TopRight | .BottomRight, cornerRadii: CGSize(width: 20.0, height: 20.0))
let bubblePath = UIBezierPath(roundedRect: bubbleSpace, cornerRadius: 20.0)
UIColor.greenColor().setStroke()
UIColor.greenColor().setFill()
bubblePath.stroke()
bubblePath.fill()
var triangleSpace = CGRectMake(0.0, self.bounds.height - 20, 20, 20.0)
var trianglePath = UIBezierPath()
var startPoint = CGPoint(x: 20.0, y: self.bounds.height - 40)
var tipPoint = CGPoint(x: 0.0, y: self.bounds.height - 30)
var endPoint = CGPoint(x: 20.0, y: self.bounds.height - 20)
trianglePath.moveToPoint(startPoint)
trianglePath.addLineToPoint(tipPoint)
trianglePath.addLineToPoint(endPoint)
trianglePath.closePath()
UIColor.greenColor().setStroke()
UIColor.greenColor().setFill()
trianglePath.stroke()
trianglePath.fill()
}
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func layoutSubviews() {
super.layoutSubviews()
// var backgroundImage = UIImageView(image: UIImage(named: "star"))
// backgroundImage.contentMode = UIViewContentMode.ScaleAspectFit
// self.backgroundView = backgroundImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment