Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from hipwelljo/iPhoneX
Browse files Browse the repository at this point in the history
Update center button position for iPhone X
  • Loading branch information
hsoi authored Sep 17, 2017
2 parents ca62d3f + 1f5b355 commit 555152f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions HELargeCenterTabBarController/HELargeCenterTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,19 @@ class HELargeCenterTabBarController: UITabBarController {
button.translatesAutoresizingMaskIntoConstraints = false
tabBar.addSubview(button)

view.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1.0, constant: 0.0));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[button]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[button(==\(unselectedImage.size.width))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[button(==\(unselectedImage.size.height))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
if #available(iOS 11.0, *) {
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
button.widthAnchor.constraint(equalToConstant: unselectedImage.size.width),
button.heightAnchor.constraint(equalToConstant: unselectedImage.size.height)
])
} else {
view.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1.0, constant: 0.0))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[button]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]));
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[button(==\(unselectedImage.size.width))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[button(==\(unselectedImage.size.height))]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["button": button]))
}

button.addTarget(self, action: #selector(centerButtonAction(_:)), for: .touchUpInside)
centerButton = button
Expand Down

0 comments on commit 555152f

Please sign in to comment.