Last active
February 16, 2017 06:49
-
-
Save nazmulkp/81996ad27b641dc179385d169d66e166 to your computer and use it in GitHub Desktop.
UITableViewCell subviews not moving when editing enabled in NSLayoutConstraint
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
override func setEditing(_ editing: Bool, animated: Bool) { | |
// Toggles the edit button state | |
super.setEditing(editing, animated: animated) | |
// Toggles the actual editing actions appearing on a table view | |
tableView.setEditing(editing, animated: true) | |
} | |
lazy var tableView : UITableView = { | |
var tv = UITableView() | |
tv.delegate = self | |
tv.dataSource = self | |
tv.backgroundColor = UIColor.yellow | |
tv.separatorStyle = UITableViewCellSeparatorStyle.none | |
tv.allowsMultipleSelectionDuringEditing = false | |
tv.translatesAutoresizingMaskIntoConstraints = false | |
return tv | |
}() | |
fileprivate class CartCell: baseTableCell { | |
var dishCategory : UILabel = { | |
var label = UILabel() | |
label.text = "Special Offers" | |
label.textColor = UIColor.black | |
//label.backgroundColor = UIColor.red | |
label.translatesAutoresizingMaskIntoConstraints = false | |
return label | |
}() | |
var dishTitle : UILabel = { | |
var label = UILabel() | |
label.text = "Burrito Drink(1)" | |
label.textColor = UIColor.black | |
//label.backgroundColor = UIColor.green | |
label.translatesAutoresizingMaskIntoConstraints = false | |
return label | |
}() | |
var dishPrice : RightPaddingLabel = { | |
var label = RightPaddingLabel() | |
label.text = "$666.50" | |
label.textColor = UIColor.black | |
label.textAlignment = .right | |
label.backgroundColor = UIColor.cyan | |
label.translatesAutoresizingMaskIntoConstraints = false | |
return label | |
}() | |
var sparteLine : UIView = { | |
var view = UIView() | |
view.backgroundColor = UIColor.blue | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
}() | |
var dishDetial : UITextView = { | |
var tv = UITextView() | |
tv.text = "The UITextView - class \n implements - the \n behavior for a scrollable -, multiline \n The UITextView - class \n implements - the \n behavior for a scrollable - \n multiline - \n" | |
tv.font = UIFont.systemFont(ofSize: 15) | |
tv.textColor = UIColor(red: 209/255, green: 209/255, blue: 209/255, alpha: 1) | |
tv.translatesAutoresizingMaskIntoConstraints = false | |
return tv | |
}() | |
var cellView : UIView = { | |
var view = UIView() | |
view.backgroundColor = .red | |
view.translatesAutoresizingMaskIntoConstraints = false | |
return view | |
}() | |
override func setupViews() { | |
print("calling cell SignUpFromCellItem") | |
//mark :- Cart | |
self.contentView.addSubview(dishCategory) // moving | |
self.contentView.addSubview(dishTitle) //not moving | |
self.contentView.addSubview(dishPrice) //not moving | |
self.contentView.addSubview(sparteLine) //not moving | |
self.contentView.addSubview(dishDetial) //not moving | |
//Mark:- dishCategory | |
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-10-[v0]-10-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : dishCategory])) | |
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-10-[v0]", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : dishCategory])) | |
//Mark:- dishTitle | |
NSLayoutConstraint(item: dishTitle, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: dishCategory, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 5).isActive = true | |
NSLayoutConstraint(item: dishTitle, attribute: NSLayoutAttribute.left, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 10).isActive = true | |
NSLayoutConstraint(item: dishTitle, attribute: NSLayoutAttribute.right, relatedBy: .equal, toItem: dishPrice, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0).isActive = true | |
//Mark:- dishPrice | |
NSLayoutConstraint(item: dishPrice, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: dishCategory, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 5).isActive = true | |
NSLayoutConstraint(item: dishPrice, attribute: NSLayoutAttribute.left, relatedBy: .equal, toItem: dishTitle, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0).isActive = true | |
NSLayoutConstraint(item: dishPrice, attribute: NSLayoutAttribute.right, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -10).isActive = true | |
NSLayoutConstraint(item: dishPrice, attribute: NSLayoutAttribute.width, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.width, multiplier: 0, constant: 80).isActive = true | |
//Mark:- sparteLine | |
NSLayoutConstraint(item: sparteLine, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: dishTitle, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 5).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: 0).isActive = true | |
NSLayoutConstraint(item: sparteLine, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 1).isActive = true | |
//Mark:- dishDetial | |
NSLayoutConstraint(item: dishDetial, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: sparteLine, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0).isActive = true | |
NSLayoutConstraint(item: dishDetial, attribute: NSLayoutAttribute.left, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 5).isActive = true | |
NSLayoutConstraint(item: dishDetial, attribute: NSLayoutAttribute.right, relatedBy: .equal, toItem: self, attribute: NSLayoutAttribute.right, multiplier: 1, constant: -10).isActive = true | |
NSLayoutConstraint(item: dishDetial, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 80).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment