【问题标题】:Can I set text under buttons in SOTabBar library?我可以在 SOTabBar 库中的按钮下设置文本吗?
【发布时间】:2020-05-23 00:37:03
【问题描述】:

我使用 SOTabBar 库,并且在文档中没有说明选项卡下的文本。有没有人使用它并在它下面设置了一些文本?

是否可以在带有 UILabel 的选项卡按钮下添加一些视图并设置文本?这不会对所有设备都有响应...That's my tab menu, at this point customers doesn't understand what tab means

【问题讨论】:

    标签: swift uitabbar swift5


    【解决方案1】:

    一个好的起点总是存储库中的示例。在不知道您当前的方法的情况下,您可以尝试类似的方法。

    class ViewController: SOTabBarController {
    
        override func loadView() {
            super.loadView()
            SOTabBarSetting.tabBarTintColor = #colorLiteral(red: 2.248547389e-05, green: 0.7047000527, blue: 0.6947537661, alpha: 1)
            SOTabBarSetting.tabBarCircleSize = CGSize(width: 60, height: 60)
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.delegate = self
            let homeStoryboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HOME_ID")
            let chatStoryboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CHAT_ID")
            let sleepStoryboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SLEEP_ID")
            let musicStoryboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MUSIC_ID")
            let meStoryboard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ME_ID")
    
            homeStoryboard.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_Selected"))
            chatStoryboard.tabBarItem = UITabBarItem(title: "Chat", image: UIImage(named: "chat"), selectedImage: UIImage(named: "chat_Selected"))
            sleepStoryboard.tabBarItem = UITabBarItem(title: "Sleep", image: UIImage(named: "moon"), selectedImage: UIImage(named: "moon_Selected"))
            musicStoryboard.tabBarItem = UITabBarItem(title: "Music", image: UIImage(named: "music"), selectedImage: UIImage(named: "music_Selected"))
            meStoryboard.tabBarItem = UITabBarItem(title: "Me", image: UIImage(named: "menu"), selectedImage: UIImage(named: "menu_Selected"))
    
            viewControllers = [homeStoryboard, chatStoryboard,sleepStoryboard,musicStoryboard,meStoryboard]
        }
    
    }
    

    如果需要,您可以通过viewController.tabBarItem.title访问这些标题

    链接到relevant example

    【讨论】:

    • 感谢您的评论@Harry J,我更好地阅读文档并解决了我的问题。
    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 2016-12-23
    • 1970-01-01
    相关资源
    最近更新 更多