Skip to content

Instantly share code, notes, and snippets.

@nazmulkp
Last active February 15, 2017 09:30
Show Gist options
  • Save nazmulkp/c0b57185f76fb426634c65eb0476889e to your computer and use it in GitHub Desktop.
Save nazmulkp/c0b57185f76fb426634c65eb0476889e to your computer and use it in GitHub Desktop.
how can i reuse UIView Swift ?
var sparteLine : UIView = {
var view = UIView()
view.backgroundColor = UIColor.blue
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
//Dish Comment
var disComment : LeftPaddingLabel = {
var label = LeftPaddingLabel()
label.text = "Commment(Optional)"
label.textColor = UIColor.black
label.textAlignment = .left
label.backgroundColor = UIColor.gray
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var disCommentTextField : LeftPaddingTextField = {
var tf = LeftPaddingTextField()
tf.backgroundColor = UIColor.darkGray
tf.borderStyle = UITextBorderStyle.roundedRect
tf.translatesAutoresizingMaskIntoConstraints = false
return tf
}()
override func setupViews(){
backgroundColor = UIColor.brown
addSubview(sparteLine)
addSubview(disComment)
addSubview(disCommentTextField)
addSubview(sparteLine)
//Mark :- sparteLine
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: dishTotal, attribute: .bottom, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.left, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.right, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier:0, constant: 5).isActive = true
//Mark:- disComment
NSLayoutConstraint(item: disComment, attribute: .top, relatedBy: .equal, toItem: sparteLine, attribute: .bottom, multiplier: 1, constant: 15).isActive = true
NSLayoutConstraint(item: disComment, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: disComment, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1, constant: -10).isActive = true
//Mark:- disCommentTextField
NSLayoutConstraint(item: disCommentTextField, attribute: .top, relatedBy: .equal, toItem: disComment, attribute: .bottom, multiplier: 1, constant: 5).isActive = true
NSLayoutConstraint(item: disCommentTextField, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: disCommentTextField, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1, constant: -10).isActive = true
NSLayoutConstraint(item: disCommentTextField, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 100).isActive = true
//Mark:- sparteLine
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: disCommentTextField, attribute: .bottom, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.left, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.right, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -10).isActive = true
NSLayoutConstraint(item: sparteLine, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier:0, constant: 5).isActive = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment