Merged PR 253045: Demo - better support for RTL
- UIView extension: fitIntoSuperview(...) supports usingLeadingTrailing = false (left/right-based constraints instead of leading/trailing) - DemoController: demo container is inserted into UIScrollView using left/right constraints, not leading/trailing due to bad support of RTL from UIScrollView - Demo list: added disclosure indicator Related work items: #708163
This commit is contained in:
Родитель
8bab56ee83
Коммит
c7f63a4587
|
@ -40,6 +40,7 @@ class DemoController: UIViewController {
|
|||
view.addSubview(scrollingContainer)
|
||||
scrollingContainer.fitIntoSuperview()
|
||||
scrollingContainer.addSubview(container)
|
||||
container.fitIntoSuperview(usingConstraints: true, autoHeight: true)
|
||||
// UIScrollView in RTL mode still have leading on the left side, so we cannot rely on leading/trailing-based constraints
|
||||
container.fitIntoSuperview(usingConstraints: true, usingLeadingTrailing: false, autoHeight: true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ class MasterViewController: UITableViewController {
|
|||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
||||
cell.textLabel!.text = demos[indexPath.row].title
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,15 +37,23 @@ public extension UIView {
|
|||
}
|
||||
}
|
||||
|
||||
func fitIntoSuperview(usingConstraints: Bool = false, margins: UIEdgeInsets = .zero, autoWidth: Bool = false, autoHeight: Bool = false) {
|
||||
func fitIntoSuperview(usingConstraints: Bool = false, usingLeadingTrailing: Bool = true, margins: UIEdgeInsets = .zero, autoWidth: Bool = false, autoHeight: Bool = false) {
|
||||
guard let superview = superview else {
|
||||
return
|
||||
}
|
||||
if usingConstraints {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
if usingLeadingTrailing {
|
||||
leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: margins.left).isActive = true
|
||||
} else {
|
||||
leftAnchor.constraint(equalTo: superview.leftAnchor, constant: margins.left).isActive = true
|
||||
}
|
||||
if autoWidth {
|
||||
if usingLeadingTrailing {
|
||||
trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: -margins.right).isActive = true
|
||||
} else {
|
||||
rightAnchor.constraint(equalTo: superview.rightAnchor, constant: -margins.right).isActive = true
|
||||
}
|
||||
} else {
|
||||
widthAnchor.constraint(equalTo: superview.widthAnchor, constant: -(margins.left + margins.right)).isActive = true
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче