【问题标题】:Custom tab button position error on iphone xiphone x上的自定义标签按钮位置错误
【发布时间】:2018-04-21 23:24:21
【问题描述】:

我将自定义按钮添加到我的标签栏,并附有 this 答案。

var menuButtonFrame: CGRect = menuButton.frame

//menuButtonFrame.origin.y = tabBar.frame.y + tabBar.frame.height - menuButtonFrame.height

menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height
menuButtonFrame.origin.x = self.view.bounds.width / 2 - menuButtonFrame.size.width / 2
menuButton.frame = menuButtonFrame

menuButton.backgroundColor = Colors.mainColor
menuButton.layer.cornerRadius = menuButtonFrame.height/2
self.view.addSubview(menuButton)

当我在模拟器上进行测试时,它运行良好。但是当我在 Iphone X 模拟器上测试时,它显示在标签栏下。

我尝试将按钮 origin.y 值与标签栏底部(注释行)对齐,但它不再起作用。

我应该使用 iphone x 特定的对齐方式还是有更干净的解决方案。

【问题讨论】:

    标签: ios iphone xcode xcode9 iphone-x


    【解决方案1】:

    不要在 UIView 中添加 centerButton。在tabBar中添加

    func addMenuButton() {
    
        let menuWidth: CGFloat = 64    //let height & width same as 64
    
        let menuButton = UIButton(frame: CGRect(x: (tabBar.frame.width / 2) - (menuWidth / 2), y: 0, width: menuWidth, height: menuWidth))
    
        menuButton.backgroundColor = .red
        menuButton.layer.cornerRadius = menuWidth/2
        tabBar.addSubview(menuButton)    //Add in tabBar instead of UIView
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多