TabbarViewController iOS中的快速中心圆按钮
在我的场景中,我尝试在UITabbarViewController中创建中心圆按钮。我尝试了许多样本,但没有得到如下图所示的输出。请提供一些代码来实现这一点。我正在使用故事板TabbarViewController iOS中的快速中心圆按钮,ios,swift,Ios,Swift,在我的场景中,我尝试在UITabbarViewController中创建中心圆按钮。我尝试了许多样本,但没有得到如下图所示的输出。请提供一些代码来实现这一点。我正在使用故事板 您需要做的是,UITabbarViewController必须在底部选项卡栏中包含五个选项卡,您可以通过添加五个视图控制器来实现,并确保中间选项卡不包含标题和图标 之后,在UITabbarViewController的onCreate方法中添加此自定义按钮代码- let button = UIButton(type
您需要做的是,UITabbarViewController必须在底部选项卡栏中包含五个选项卡,您可以通过添加五个视图控制器来实现,并确保中间选项卡不包含标题和图标 之后,在UITabbarViewController的onCreate方法中添加此自定义按钮代码-
let button = UIButton(type: .custom)
var toMakeButtonUp = 40
button.frame = CGRect(x: 0.0, y: 0.0, width: 65, height: 65)
button.setBackgroundImage(ADD, for: .normal)
button.setBackgroundImage(ADD, for: .highlighted)
let heightDifference: CGFloat = CGFloat(toMakeButtonUp)
if heightDifference < 0 {
button.center = tabBar.center
} else {
var center: CGPoint = tabBar.center
center.y = center.y - heightDifference / 2.0
button.center = center
}
button.addTarget(self, action: #selector(btnTouched), for:.touchUpInside)
view.addSubview(button)
let button=ui按钮(类型:。自定义)
变量toMakeButtonUp=40
button.frame=CGRect(x:0.0,y:0.0,宽度:65,高度:65)
button.setBackgroundImage(添加,用于:。正常)
button.setBackgroundImage(添加,用于:。高亮显示)
让高度差:CGFloat=CGFloat(toMakeButtonUp)
如果高度差<0{
button.center=tabBar.center
}否则{
变量中心:CGPoint=tabBar.center
center.y=center.y-高度差/2.0
按钮。中心=中心
}
addTarget(self,action:#选择器(btn已接触),用于:。touchUpInside)
view.addSubview(按钮)
仅供参考-toMakeButton是底部的边距,您可以相应地进行设置。
#selector(btnTouched)是类中定义的函数,单击按钮将执行该函数
我想已经回答了可能的重复问题