Tunnel creation: Fix Persistent Keepalive label's look

This commit is contained in:
Roopesh Chander 2018-10-22 13:49:21 +05:30
parent bbd13ad4cf
commit d831bd44c4
1 changed files with 4 additions and 14 deletions

View File

@ -225,7 +225,6 @@ extension TunnelEditTableViewController {
case .endpoint: case .endpoint:
break break
case .persistentKeepAlive: case .persistentKeepAlive:
cell.hasLongKey = true
break break
case .allowedIPs: case .allowedIPs:
break break
@ -320,16 +319,6 @@ class TunnelsEditTableViewKeyValueCell: UITableViewCell {
keyLabel.textColor = value ? UIColor.black : UIColor.gray keyLabel.textColor = value ? UIColor.black : UIColor.gray
} }
} }
var hasLongKey: Bool {
get { return modifiableWidthRatioConstraint!.constant > 0 }
set(value) {
if (value) {
modifiableWidthRatioConstraint!.constant = 40
} else {
modifiableWidthRatioConstraint!.constant = 0
}
}
}
var isValueValid: Bool = true { var isValueValid: Bool = true {
didSet(value) { didSet(value) {
if (value) { if (value) {
@ -342,7 +331,6 @@ class TunnelsEditTableViewKeyValueCell: UITableViewCell {
let keyLabel: UILabel let keyLabel: UILabel
let valueTextField: UITextField let valueTextField: UITextField
private var modifiableWidthRatioConstraint: NSLayoutConstraint? = nil
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
keyLabel = UILabel() keyLabel = UILabel()
@ -355,12 +343,15 @@ class TunnelsEditTableViewKeyValueCell: UITableViewCell {
relatedBy: .equal, relatedBy: .equal,
toItem: self, attribute: .width, toItem: self, attribute: .width,
multiplier: 0.4, constant: 0) multiplier: 0.4, constant: 0)
// The "Persistent Keepalive" key doesn't fit into 0.4 * width on the iPhone SE,
// so set a CR priority > the 0.4-constraint's priority.
widthRatioConstraint.priority = .defaultHigh + 1
keyLabel.setContentCompressionResistancePriority(.defaultHigh + 2, for: .horizontal)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
keyLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor), keyLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
keyLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 8), keyLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 8),
widthRatioConstraint widthRatioConstraint
]) ])
modifiableWidthRatioConstraint = widthRatioConstraint
contentView.addSubview(valueTextField) contentView.addSubview(valueTextField)
valueTextField.translatesAutoresizingMaskIntoConstraints = false valueTextField.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
@ -380,7 +371,6 @@ class TunnelsEditTableViewKeyValueCell: UITableViewCell {
value = "" value = ""
placeholderText = "" placeholderText = ""
isValueEditable = true isValueEditable = true
hasLongKey = false
isValueValid = true isValueValid = true
} }
} }