Created
December 7, 2015 17:05
-
-
Save alonecuzzo/d5905f830bcdc91fbefd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomTableHeaderView: UIView { | |
//MARK: Property | |
let label = UILabel(frame: CGRectZero) | |
let backbutton = UIButton(frame: CGRectZero) | |
//MARK: Method | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
label.text = "Add custom location" | |
label.textAlignment = .Center | |
backbutton.setImage(UIImage(named: "icon-backArrow-black"), forState: UIControlState.Normal) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
//TODO: Remove adding of subviews etc | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
label.frame = self.frame | |
backbutton.frame = CGRect(x: 16, y: 0, width: 20, height: self.frame.height) | |
self.addSubview(label) | |
self.addSubview(backbutton) | |
let border = CALayer() | |
let width = CGFloat(0.8) | |
//default gray color on UITableViewSeparator | |
border.borderColor = UIColor(red: 0.783922, green: 0.780392, blue: 0.8, alpha: 1.0).CGColor | |
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: self.frame.size.height) | |
border.borderWidth = width | |
self.layer.addSublayer(border) | |
self.layer.masksToBounds = true | |
} | |
} |
don't forget that layoutSubviews()
can get called multiple times on a view, so we don't want to add subviews or do any sort of configuration other than reframing/repositioning in there... any border
properties like color and size should be moved to the setup()
function as well
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the
remove the
fatalError
and pop insuper.init(coder: aDecoder)
and then you can add yoursetup()
function in there after thesuper.init(coder: aDecoder)
gets called