I am developing an app in Swift. In my Storyboard, I have a UITableViewController. I would like to apply left and right margins to my table as well as rounded corners on first/last cells and a shadow all around the tableview.
I have tried many options, but I cannot find a proper solution. Right now, I am using a subclass of UITableViewCell where I override the frame to make it narrower. I can have the rounded corners but I cannot have the shadow.
Here is my code for my sublcass:
class NarrowTableCell: UITableViewCell {
override var frame: CGRect {
get {
return super.frame
}
set (newFrame) {
var f = newFrame
f.origin.x = 10
if let w = superview?.frame.size.width {
f.size.width = w - 20
} else {
f.size.width = newFrame.size.width - 20
}
super.frame = f
super.layer.masksToBounds = true
}
}
func applyNoCorners() {
round(corners: [.topLeft, .topRight, .bottomLeft, .bottomRight], radius: 0)
}
func applyCorners() {
round(corners: [.topLeft, .topRight, .bottomLeft, .bottomRight], radius: 5)
}
func applyTopCorners() {
round(corners: [.topLeft, .topRight], radius: 5)
}
func applyBottomCorners() {
round(corners: [ .bottomLeft, .bottomRight], radius: 5)
}
}
I am doing most of my app in Storyboard and I would like to be able to achieve the same results for both dynamic and static tableviews.
Another issue I have is that when the cell frame is changed, the label I have inside is not properly updated. That means, its contente is truncated.
Here is what I would like to do: