具体内容详情如下所示:
-
<李>以分类的方式实现李>
代码
UITabBar + Extenstion.swift
fileprivate让lxfFlag: Int=666 扩展UITabBar {//马克:-显示小红点 func showBadgOn(索引itemIndex: Int, tabbarItemNums: CGFloat=4.0) {//移除之前的小红点 自我。removeBadgeOn(指数:itemIndex)//创建小红点 让bageView=UIView () bageView。标签=itemIndex + lxfFlag bageView.layer。cornerRadius=5 bageView。写成backgroundColor=UIColor.red 让tabFrame=self.frame//确定小红点的位置 让percentX: CGFloat=(CGFloat (itemIndex) + 0.59)/tabbarItemNums 让x: CGFloat=CGFloat (ceilf(浮动(percentX * tabFrame.size.width))) 让y: CGFloat=CGFloat (ceilf(浮动(0.115 * tabFrame.size.height))) bageView.frame=CGRect中(x, x, y, y,宽度:10日身高:10) self.addSubview (bageView) }//马克:-隐藏小红点 func hideBadg (itemIndex: Int) {//移除小红点 自我。removeBadgeOn(指数:itemIndex) }//马克:——移除小红点 fileprivate func removeBadgeOn(指数itemIndex: Int) {//按照标签值进行移除 _=子视图。{地图 如果$ 0。标签==itemIndex + lxfFlag { 0.美元removefromsuperview () } } } }
<强>使用强>
//默认4个tabbarItem self.tabBarController& # 63; .tabBar。showBadgOn(指数:2)//如果不是则用这个方法//self.tabBarController& # 63; .tabBar。showBadgOn(指数:Int, tabbarItemNums: CGFloat)
<>强效果强>
小红点
以上所述是小编给大家介绍的iOS中迅速仿微信添加提示小红点功能(无数字),希望对大家有所帮助,如果大家有任何疑问请给我留的言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!