Category:Music download managers
Category:2016 softwareQ:
Custom Cell with custom overlay in iOS 9
I want to create custom cell with a custom overlay and add the overlay on top of my cell.
Here is the code :
ViewController.swift :
import UIKit
class ViewController: UIViewController {
let cell = UITableViewCell()
override func viewDidLoad() {
super.viewDidLoad()
cell.layer.cornerRadius = 8
cell.backgroundColor = UIColor.blue
// Add a overlay
cell.layer.addSublayer(
CALayer()
)
}
}
ViewController.xib :
ViewController.swift :
import UIKit
class ViewController: UIViewController {
let cell = UITableViewCell()
override func viewDidLoad() {
super.viewDidLoad()
cell.layer.cornerRadius = 8
cell.backgroundColor = UIColor.blue
// Add a overlay
cell.layer.addSublayer(
CALayer()
)
}
}
I don't see any result...
What do you think?
A:
I suggest a completely different approach. Instead of extending UITableViewCell create your own custom class which inherits from UIView and adds some extra data to it.
Then you can create the cell and add it in a custom tableViewController.
Here's an example:
class MyCell: UIView {
var title: String?
var subtitle: String?
func setTitle(title: String) {
self.title = title
}
func setSubtitle(subtitle: String) {
self.subtitle = subtitle
}
override init(frame: CGRect) { be359ba680
Related links:
Comments