我正在构建一个电子商务应用,并希望创建附加图像。sources
我现在提出这个控制器,因此它不会出现在Tabbar中。
我是否有一种简单的方法可以添加Tabbar并创建按钮,而无需为每个iPhone创建类似TabBar的视图?
或者最好将它嵌入另一个UITabBarController中?似乎过度杀伤......
非常感谢。
答案 0 :(得分:0)
声明Checkout按钮和工具栏的视图&阴影。
lazy var customView: UIView = {
let vw = UIView()
vw.backgroundColor = UIColor(red: 249/255, green: 249/255, blue: 249/255, alpha: 1.0)
vw.translatesAutoresizingMaskIntoConstraints = false
return vw
}()
lazy var shadowView: UIView = {
let vw = UIView()
vw.backgroundColor = UIColor.gray
vw.translatesAutoresizingMaskIntoConstraints = false
return vw
}()
lazy var checkoutButton: UIButton = {
let btn = UIButton(type: .system)
btn.tintColor = .white
btn.layer.cornerRadius = 5
btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
btn.setTitle("Checkout", for: .normal)
btn.backgroundColor = UIColor(red: 39/255, green: 39/255, blue: 39/255, alpha: 1.0)
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
在viewDidLoad中添加all。
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(customView)
[customView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
//Size of UITabBar from safeArea, so its compatible for iPhone X and others
customView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -49),
customView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
customView.heightAnchor.constraint(equalToConstant: 83)].forEach{ $0.isActive = true }
view.addSubview(shadowView)
[shadowView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
shadowView.bottomAnchor.constraint(equalTo: customView.topAnchor),
shadowView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
shadowView.heightAnchor.constraint(equalToConstant: 0.5)].forEach{ $0.isActive = true }
customView.addSubview(checkoutButton)
[checkoutButton.leadingAnchor.constraint(equalTo: customView.leadingAnchor, constant: 10),
checkoutButton.topAnchor.constraint(equalTo: customView.topAnchor, constant: 4.5),
checkoutButton.trailingAnchor.constraint(equalTo: customView.trailingAnchor, constant: -10),
checkoutButton.heightAnchor.constraint(equalToConstant: 40)].forEach{ $0.isActive = true }
}