I am using custom TableCell which has a label with numberofLines = 0
I wanted the label like this.
That is rounded only in three corners.For this to achieve i've written code like this in cell's swift file.I've extended the UIView basically.
extension UIView {
func roundCorners(corners:UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
And i've used this like this to round my corners.
self.chatLabel.roundCorners(corners: [.topLeft,.bottomLeft,.bottomRight], radius: 7.0)
But the problem is when label's content is bigger than the cell's row height it's not showing the content
Please just see the second cell's label in first picture .It's content is not showing. But when i remove the rounded corner's code everything is working fine but lost my corner radius.
Any suggestion is highly appreciated.Thanks.
Edited:
My cell is like this.
And i am achieving chat UI using the code below.
var cellTypeToDraw:cellType {
get {
return self.cellTypeToDraw
}
set(newValue) {
switch newValue {
case .cellTypeReceiver:
self.leftImage.isHidden = true
self.rightImage.isHidden = false
self.chatLabel.textAlignment = .right
self.chatLabel.roundCorners(corners: [.topLeft,.bottomLeft,.bottomRight], radius: 7.0)
case .cellTypeSender:
self.rightImage.isHidden = true
self.leftImage.isHidden = false
self.chatLabel.textAlignment = .left
self.chatLabel.roundCorners(corners: [.topRight,.bottomLeft,.bottomRight], radius: 7.0)
}
self.leftImage.layer.cornerRadius = self.leftImage.bounds.size.width/2
self.rightImage.layer.cornerRadius = self.rightImage.bounds.size.width/2
// self.chatLabel.sizeToFit()
// self.chatLabel.autoresizingMask = .flexibleHeight
}
}
and accessing this variable in cellForRowAtIndexPath like this.
if indexPath.row % 2 != 0 {
cell.cellTypeToDraw = .cellTypeReceiver
}
else {
cell.cellTypeToDraw = .cellTypeSender
}