更改MoreNavigationController TableView行中的徽章值文本和背景颜色?

时间:2018-10-29 15:44:31

标签: ios swift uitableview uinavigationcontroller uitabbarcontroller

我已经完全自定义了MoreNavigationController,但是我无法弄清楚最后一点...如何更改表视图行的标志文本和背景颜色?看到下面的图片...

BadgeColor

1 个答案:

答案 0 :(得分:0)

想通了...添加到您的tabBarController类中:

UINavigationControllerDelegate

然后设置:

moreNavigationController.delegate = self

然后添加此内容:

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        if (self.moreNavigationController.topViewController?.title == "More"){
            let moreTableView = self.moreNavigationController.topViewController!.view as! UITableView

            for cell in moreTableView.visibleCells {

                for views in cell.subviews {

                   // print(views.description.contains("_UITableViewCellBadgeNeue"))

                    for items in views.subviews {
                        if (items is UILabel) {
                            let item = items as! UILabel
                            item.textColor = UIColor.white
                            item.backgroundColor = UIColor(red: 27, green: 27, blue: 27, transparancy: 100)
                        }
                    }
                }
            }
        }
    }