【问题标题】:Customise Tab Bar with rounded button Issue swift使用圆形按钮自定义标签栏问题 swift
【发布时间】:2021-02-14 20:12:29
【问题描述】:

我一直在自定义带有圆形按钮的标签栏并设置圆角半径曲线,我在情节提要中设置如下,

我已将图像渲染为原始图像,但我的问题是当我在模拟器中运行时,圆形圆圈的上半部分缺失,如图所示,

我已经为 UITabBar 设置了类,

class ProminentTabBar: UITabBar {
    var prominentButtonCallback: (()->())?
    
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        guard let items = items, items.count>0 else {
            return super.hitTest(point, with: event)
        }
        
        let middleItem = items[items.count/2]
        let middleExtra = middleItem.imageInsets.top
        let middleWidth = bounds.width/CGFloat(items.count)
        let middleRect = CGRect(x: (bounds.width-middleWidth)/2, y: middleExtra, width: middleWidth, height: abs(middleExtra))
        if middleRect.contains(point) {
            prominentButtonCallback?()
            return nil
        }
        return super.hitTest(point, with: event)
    }
}

并且 tabbarcontroller 也添加到下面的行中,

override func viewDidLoad() {
    super.viewDidLoad()
    
    let prominentTabBar = self.tabBar as! ProminentTabBar
    prominentTabBar.prominentButtonCallback = prominentTabTaped
}

func prominentTabTaped() {
    selectedIndex = (tabBar.items?.count ?? 0)/2
}

此来源来自堆栈溢出票证:- How do we create a bigger center UITabBar Item

有没有人可以解决这个问题>?

【问题讨论】:

    标签: ios iphone ios7 swift4 swift5


    【解决方案1】:

    制作

    tabbar.clipsToBounds = false
    

    您可以通过代码或在 StoryBoard 中更改它

    继续编码...... :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      相关资源
      最近更新 更多