Last active
August 9, 2019 01:27
-
-
Save Haeuncs/f6a71299369d7870d450b6a1f03b4198 to your computer and use it in GitHub Desktop.
UITableView Custom BackGoundView
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
// | |
// TableViewBackgroundView.swift | |
// Fitco | |
// | |
// Created by OOPSLA on 25/05/2019. | |
// Copyright © 2019 Cho. All rights reserved. | |
// | |
import Foundation | |
class tableViewBackGroundView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
initView() | |
} | |
func initView(){ | |
self.backgroundColor = .white | |
addSubview(closetDescriptionLeftLineView) | |
addSubview(closetDescriptionLabel) | |
addSubview(closetDescriptionRightLineView) | |
if hasTopNotch { | |
closetDescriptionLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -58).isActive = true | |
}else{ | |
closetDescriptionLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -24).isActive = true | |
} | |
NSLayoutConstraint.activate([ | |
closetDescriptionLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor), | |
// closetDescriptionLabel.bottomAnchor.constraint(equalTo: self.layoutMarginsGuide.bottomAnchor, constant: 0), | |
closetDescriptionLeftLineView.heightAnchor.constraint(equalToConstant: 1), | |
closetDescriptionLeftLineView.centerYAnchor.constraint(equalTo: closetDescriptionLabel.centerYAnchor), | |
closetDescriptionLeftLineView.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 20), | |
closetDescriptionLeftLineView.trailingAnchor.constraint(equalTo: closetDescriptionLabel.leadingAnchor, constant: -9), | |
closetDescriptionRightLineView.heightAnchor.constraint(equalToConstant: 1), | |
closetDescriptionRightLineView.centerYAnchor.constraint(equalTo: closetDescriptionLabel.centerYAnchor), | |
closetDescriptionRightLineView.leadingAnchor.constraint(equalTo: closetDescriptionLabel.trailingAnchor, constant: 9), | |
closetDescriptionRightLineView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20), | |
]) | |
} | |
lazy var closetDescriptionView : UIView = { | |
let view = UIView() | |
// view.isHidden = true | |
view.backgroundColor = .red | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
}() | |
lazy var closetDescriptionLeftLineView : UIView = { | |
let view = UIView() | |
view.backgroundColor = #colorLiteral(red: 0.8588235294, green: 0.8595622778, blue: 0.8590090275, alpha: 1) | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
}() | |
lazy var closetDescriptionLabel : UILabel = { | |
let label = UILabel() | |
label.text = "+ 버튼을 눌러 옷을 추가해 보면 어떠세요?" | |
label.textColor = UIColor.FitcoColor.DefaultColor.TextColor112 | |
label.font = UIFont.systemFont(ofSize: 13, weight: .bold) | |
label.translatesAutoresizingMaskIntoConstraints = false | |
return label | |
}() | |
lazy var closetDescriptionRightLineView : UIView = { | |
let view = UIView() | |
view.backgroundColor = #colorLiteral(red: 0.8588235294, green: 0.8595622778, blue: 0.8590090275, alpha: 1) | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
}() | |
} | |
//USAGE | |
let backview = tableViewBackGroundView() | |
yourTableView.backgroundView = backview | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Default hide Backgound
![](https://user-images.githubusercontent.com/39240556/62342196-8726a000-b4d5-11e9-9c0c-932678a96be8.PNG)
![](https://user-images.githubusercontent.com/39240556/62342204-8e4dae00-b4d5-11e9-9bb0-b11b76deaa9a.PNG)
scroll