Skip to content

Instantly share code, notes, and snippets.

@Haeuncs
Last active August 9, 2019 01:27
Show Gist options
  • Save Haeuncs/f6a71299369d7870d450b6a1f03b4198 to your computer and use it in GitHub Desktop.
Save Haeuncs/f6a71299369d7870d450b6a1f03b4198 to your computer and use it in GitHub Desktop.
UITableView Custom BackGoundView
//
// 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
@Haeuncs
Copy link
Author

Haeuncs commented Aug 2, 2019

Default hide Backgound

scroll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment