You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This page collects the usage questions from GitHub Issues labeled Q-A. The original issues are closed; each entry links to them for the full discussion.
For usage questions, check this page and the README first, and open an issue only if they don't help. Report bugs and feature requests as issues directly.
The library is written in Objective-C and works in Swift projects as is. The repository has several Swift demos (the Example-Swift* directories); see Using CYLTabBarController in a Swift project in the README, and the Swift guide for full setup and API examples in Swift (including fixes for import errors, #282).
[CN]控制台打印 Class CYLTabBar overrides the -traitCollection getter, which is not supported
[EN]The console prints Class CYLTabBar overrides the -traitCollection getter, which is not supported
Old versions of CYLTabBar overrode -traitCollection, which iOS 13 and later warn about. That code has been removed. If the warning remains after upgrading:
1. Xcode 中执行 Clean Build Folder 后重新编译;
1. Run Clean Build Folder in Xcode and build again.
2. 确认 Podfile.lock 中的版本确实已更新(可先注释该依赖 pod install,再取消注释重新 pod install)。
2. Check that Podfile.lock really has the new version (comment out the dependency and run pod install, then uncomment it and run pod install again).
The library does not affect breakpoints. Check that the scheme's Build Configuration is Debug, and the Debug Information Format and Optimization Level build settings (Debug should be None [-O0]).
Yes. With unloadsUnselectedViewsOnMemoryWarning on (default NO), a memory warning unloads the views of the unselected tabs; UIKit runs -loadView / -viewDidLoad again when the tab is selected. The view controllers stay in viewControllers, so tab bar items, badges, Lottie icons and navigation stacks are kept.
// In a CYLTabBarController subclass, e.g. in -viewDidLoad
self.unloadsUnselectedViewsOnMemoryWarning = YES;
// Optional: keep some tabs loaded, e.g. one whose -viewDidLoad must run only once
- (BOOL)shouldUnloadViewOfViewController:(UIViewController *)viewController {
return viewController != self.viewControllers.firstObject;
}
Rules: the selected tab is kept; a UINavigationController tab is unloaded with its whole stack, or kept as a whole; a tab is skipped while any of its pages is on screen or presenting another one; a tab for which -shouldUnloadViewOfViewController: returns NO is kept.
Only turn it on when those pages' -viewDidLoad can run again (it only builds views and does not register observers or timers a second time); otherwise keep the tab with -shouldUnloadViewOfViewController:. You can also call -unloadViewsOfUnselectedViewControllers directly at other times, e.g. after the app enters the background.
With it off, the library unloads nothing; release large resources (images, caches) in each child view controller's -didReceiveMemoryWarning and load them again in -viewWillAppear:.
Testing: +[CYLTabBarController cyl_simulateMemoryWarning] simulates a memory warning with public API only: it posts UIApplicationDidReceiveMemoryWarningNotification, calls the app delegate's and the most recently active tab bar controller's -didReceiveMemoryWarning (posting the notification alone does not call it), then logs each tab's badge state and Lottie speed. For a given tab bar controller, use +cyl_simulateMemoryWarningForTabBarController:.
Demo: in the ObjC demo, the "模拟内存警告 Memory warning" row at the top of each list (UIViewController+CYLMemoryWarning, -cyl_simulateMemoryWarningAndShowResult, in the settings section CYLSettingsSection) simulates a memory warning for its tab bar controller and shows in an alert whether each tab was unloaded and why not; selecting an unloaded tab then runs its -viewDidLoad again. In the Swift demos, tapping a cell of the badge list calls cyl_simulateMemoryWarning and logs the state. Works in the classic, Liquid Glass and flat design styles.
Configuration files, cross-platform: CYLTabBarControllerUnloadsUnselectedViewsOnMemoryWarning (a boolean) turns unloading on and CYLTabBarControllerKeepsLoadedTabBarItemIdentifiers (a list of identifiers, cyl_keepsLoadedTabBarItemIdentifiers) keeps some tabs, without a subclass; CYLSimulateMemoryWarningReport() (iOS / Android) simulates a memory warning and returns what happened to each tab, the alert above. CYLTabBarHostView's simulateMemoryWarning and the React Native and Flutter components' memoryWarningRequest / onMemoryWarning use it; the examples' "Simulate memory warning" row works as the ObjC Demo's and keeps the home tab.
[CN]TabBar 超过 5 个 item 时,如何隐藏 More 按钮?
[EN]How do I hide the More button with more than five items?
The system UITabBar shows at most five items and adds More beyond that; this is system behavior and an App Review requirement. The PlusButton does not count, so the limit is five TabBarItems plus one PlusButton; see Why does placing six TabBarItems behave unexpectedly? in the README.
Fixed on 2026-11-10: with more than five tabs the classic style and Liquid Glass used to show only the first five and no More, so the sixth tab and later could not be reached (that path installs tabs with -addChildViewController:, and UIKit builds More in -setViewControllers: only for view controllers that are not children yet). More than five tabs now give a More tab as the system UITabBarController does, and the tabs under More can be selected and edited; five or fewer are unchanged. Screenshots in Liquid-Glass-Robustness. Staying within five, or the overflow slot below, is still recommended.
Avoiding the system More: UIKit adds More by itself once there are more than five view controllers, and it cannot be turned off, so give the tab bar controller five view controllers and use the fifth tab as an overflow slot. With the custom tab action API (cyl_shouldPerformCustomTabActionHandler + cyl_customTabActionHandler, see Tab-Custom-Action.md), tapping the slot shows your own menu of the pages that do not fit; the chosen page goes into the slot with its own title and icon through -replaceViewControllerAtIndex:withViewController:attributes: and is selected. While another tab is selected, tapping the slot opens its page directly; tapping it again shows the menu. The tab bar always has five tabs, every page is reachable, and there is no system More list.
示例:ObjC Demo 的「Tab Bar Gallery」→「More than five tabs」→「8 tabs without the system "More"」(+overflowMenuScene,Example/Classes/Gallery/CYLGalleryProvider.m),同组第二行是系统 More 的对照。
Example: the ObjC demo's "Tab Bar Gallery" → "More than five tabs" → "8 tabs without the system "More"" (+overflowMenuScene in Example/Classes/Gallery/CYLGalleryProvider.m); the second row of that section shows the system More for comparison.
// [EN] Five view controllers; the fifth (identifier "overflow") is the slot. [CN] 五个视图控制器;第五个(identifier 为 "overflow")是溢出位。
tabBarController.cyl_shouldPerformCustomTabActionHandler = ^BOOL(CYLTabBarController *controller, UIViewController *viewController) {
NSUInteger index = [controller.viewControllers indexOfObject:viewController];
return index == 4 && (viewController == placeholder || controller.selectedIndex == 4);
};
tabBarController.cyl_customTabActionHandler = ^(CYLTabBarController *controller, UIViewController *viewController) {
// [EN] Show a menu of the other pages; on a choice: [CN] 弹出其他页面的菜单;选中某项时:
[controller replaceViewControllerAtIndex:4withViewController:page attributes:pageAttributes];
controller.selectedIndex = 4;
};
[CN]3. PlusButton(中间凸起按钮)
[EN]3. PlusButton (the raised center button)
[CN]照着 README 写了,中间按钮却不显示
[EN]The center button does not show although I followed the README
1. Call [YourPlusButtonSubclass registerPlusButton] in -application:didFinishLaunchingWithOptions:, before creating the CYLTabBarController (not in +load; see Why does it crash on iOS 10 but not iOS 9? in the README).
In old versions, selecting the PlusButton's page in code selected the system tab button under the PlusButton, which looks like the neighboring item. This is fixed; upgrade to the latest version.
[CN]默认选中 PlusButton 后,点击其他 Tab,PlusButton 无法恢复 normal 状态
[EN]After selecting the PlusButton at launch, it stays selected when another tab is tapped
Don't set CYLExternPlusButton.selected yourself; select it with selectedIndex as above and the library keeps the state. With a custom UITabBarControllerDelegate, sync the state in -tabBarController:shouldSelectViewController: as described in PlusButton remains selected after selecting another tab.
The library builds on the system UITabBar for "several TabBarItems plus an optional PlusButton", and does not support a TabBar with only a PlusButton. Put a custom button at the bottom of the page instead.
[CN]中间凸起按钮上的白边、阴影怎么设置?
[EN]How do I add a white border or shadow to the raised button?
The white border in the demo is part of the icon image. Use an image with the border, or set borderColor, shadowColor and so on on the button's layer in +plusButton.
[CN]只能有一个 PlusButton?全局静态变量导致一个 App 只能用一个实例
[EN]Only one PlusButton? Global variables limit an app to one instance
Several TabBarControllers can now each have their own PlusButton: a PlusButton is bound to its TabBarController by context, and each TabBar keeps its own layout data such as item count and width. See Nesting multiple TabBars and specifying the PlusButton position in the README.
Icons are shown at the image's own size; provide @2x/@3x images at the designed size. To fine-tune the position, use CYLTabBarItemImageInsets in tabBarItemsAttributes.
imageInsets 的 top 与 bottom 必须大小相等、符号相反,例如 UIEdgeInsetsMake(offset, 0, -offset, 0)。否则系统每次布局都会改变图片尺寸。
The top and bottom of imageInsets must be equal and opposite, for example UIEdgeInsetsMake(offset, 0, -offset, 0). Otherwise the system resizes the image on every layout pass.
[CN]只显示图标时,图标没有垂直居中;只显示文字(类似抖音)怎么做?
[EN]Icons are not vertically centered without titles; how do I show titles only (like TikTok)?
Titles only: without an image, the library uses a placeholder image (+[UIImage cyl_tabItemPlaceholderImage]) to keep the layout. Move the title to the vertical center with CYLTabBarItemTitlePositionAdjustment, or render the text as an image and treat it as an icon.
[CN]能否让图标和标题水平排列(图标在左、标题在右)?
[EN]Can the icon and title sit side by side (icon left, title right)?
The system uses the side-by-side (inline) layout only on wide screens such as iPad, and the library has no option to force it on iPhone. Replace the tab button with a custom view using -[UIControl cyl_replaceTabButtonWithNewView:show:].
[CN]iPad 上 item 都挤在中间,如何让它们平分宽度?
[EN]On iPad the items are packed in the middle; how do I spread them across the width?
This is the default layout of the system UITabBar on iPad. Set (and the other way round: centered tabs, an item width and spacing, or space at both ends also work on the classic tab bar with a plus button, see Tab-Item-Positioning.md):
The system draws selectionIndicatorImage over the item's area; it does not follow the title offset. Build the offset into the image itself; for a custom selected background, see How can I add a selected background color? in the README.
系统会把渲染模式为 Automatic 的图片当作模板图,按 tint color 着色,图标就变成单色剪影(#465 的截图)。希望显示图片原色时:
The system treats images with the Automatic rendering mode as templates and tints them, so icons turn into one-color silhouettes (the screenshots in #465). To show the image's own colors:
1. Pass the image name (NSString) instead of a UIImage in tabBarItemsAttributes (recommended): the library renders it as original and loads its dark image, which is how #465 was solved; or
2. 在 Asset Catalog 中把图片的 Render As 设为 Original Image;或
2. Set Render As to Original Image for the image in the asset catalog; or
Since iOS 13, use UITabBarAppearance, and set titlePositionAdjustment on the appearance too, or CYLTabBarItemTitlePositionAdjustment stops working. As in the demo's MainTabBarController.m:
Typical symptom (#258): the first time a tab is selected, its title flickers and then turns into that page's navigation bar title. The tab's page runs viewDidLoad only when it is first selected, and the self.title = ... in it is copied by UIKit into tabBarItem.title (and into the navigation controller's tabBarItem when the page is its root), so the TabBar lays out again with the new text. This is UIKit behavior; CYLTabBarController does not change tab titles when switching tabs.
Fix: in the page, set only navigationItem.title; set the tab text only through CYLTabBarItemTitle in tabBarItemsAttributes. If you must use self.title, make it exactly equal to CYLTabBarItemTitle. The Swift demos (Example-Swift-03, Example-Swift-Carthage, Example-SwiftUI) now use navigationItem.title.
- (void)viewDidLoad {
[superviewDidLoad];
self.navigationItem.title = CYLLocalizedString(@"首页"); // ✅ only the navigation bar// self.title = @"首页"; // ❌ also rewrites the tab title (#258)
}
overridefuncviewDidLoad(){super.viewDidLoad()navigationItem.title=CYLLocalizedString("首页") // ✅ only the navigation bar
// title = "首页" // ❌ also rewrites the tab title (#258)
}
[CN]5. 外观:背景、分割线、阴影与深色模式
[EN]5. Appearance: background, separator, shadow and Dark Mode
[CN]如何隐藏 TabBar 顶部分割线、自定义分割线颜色,或给 TabBar 加阴影?
[EN]How do I hide the top separator, change its color, or add a shadow to the TabBar?
Custom separator: since iOS 13, set shadowColor (fixed 1pt height) or shadowImage (custom height) on UITabBarAppearance; see #494 and the demo's MainTabBarController.m.
On devices without a Home button the TabBar is taller (it includes the bottom safe area), so fit the image to the real height or use a resizable image. Areas outside the TabBar don't receive taps; see A raised icon does not respond above 49pt in the README.
[CN]iOS 13 起用 KVC 设置 TabBar 会崩溃吗?
[EN]Does setting TabBar properties through KVC crash since iOS 13?
Since iOS 13, accessing some private properties through KVC (such as _xxx instance variables) crashes. Use public APIs such as UITabBarAppearance instead of KVC.
[CN]深色模式(Dark Mode)如何适配?动态颜色、图片不跟随切换
[EN]How do I support Dark Mode? Dynamic colors and images don't switch
Colors: use dynamic colors, such as the system systemBackgroundColor or the library's cyl_systemBackgroundColor, cyl_labelColor and others (see UIColor+CYLTabBarControllerExtention.h); for a light and a dark color, newer versions add +[UIColor cyl_colorWithLightColor:darkColor:]. Don't check the current mode yourself and pass a fixed color: at that point the trait may still be unspecified (the cause of #552).
Images: add a Dark appearance to the image in the asset catalog, and pass the image name in tabBarItemsAttributes; in newer versions, also provide <name>_dark by naming convention (loaded automatically with the name), or combine two images into one that switches by itself with +[UIImage cyl_imageWithLightImage:darkImage:], instead of replacing them in -traitCollectionDidChange: (the older workaround in #486).
You can also set window.overrideUserInterfaceStyle (or on the window's root view controller). If things still follow only the system after that, the code usually picks images or colors by the window scene's or the screen's style, which ignore the window's override. The old demo's -traitCollectionDidChange: and the library's internal (unpublished) light/dark image helper did so; newer versions follow each view's own style. Compare self.traitCollection, and use images and colors that switch by themselves (see the entry above).
The cause was not found in the original issue. Badges have been reworked since: they re-resolve their border color and restore their repeating animation when traits such as Dark Mode change, and their default colors can be set globally with CYLBadgeAppearance. Upgrade to the latest version and try again; if it still happens, report a bug with a demo that reproduces it.
[CN]6. 角标 Badge
[EN]6. Badges
[CN]设置角标字体后,角标大小也变了
[EN]Changing the badge font also changes the badge size
The badge size follows its text and font; this is expected. For a fixed size, set cyl_badgeFrame, cyl_badgeRadius and similar properties (see CYLBadgeProtocol.h), or, as the reporter did, add your own label to cyl_tabButton.cyl_tabImageView.
[CN]如何全局设置角标的背景色等属性?
[EN]How do I set the badge background color and other properties globally?
Newer versions add CYLBadgeAppearance: set it once before showing badges; a value set on an object still wins. See Setting the badge style globally in the README.
The usual cause is a subclass whose -init creates and returns another CYLTabBarController (as the old README did): the app shows that plain instance, and the block set in the subclass's -viewDidLoad lands on a discarded object and never runs. Initialize through [super initWithViewControllers:…] as in Step 2 of the README.
To show or update tab badges, use -reloadBadgesWithBlock: instead: call it any time, as often as needed; it runs once the tab buttons exist, with no dispatch_after. The once-block holds a single block, and one set after the tab bar was laid out may never run. See Updating tab badges in the README.
可以在 LottieFiles 查找或在线编辑,也可由设计师用 After Effects + Bodymovin 导出。商用前请确认素材的授权。
Find or edit animations online at LottieFiles, or have a designer export them from After Effects with Bodymovin. Check the license before commercial use.
[CN]能否运行时替换某个 Tab 的 Lottie 动画?
[EN]Can a tab's Lottie animation be replaced at runtime?
All tabs: set lottieAnimationSpeed (default 1.0; 0, negative or non-finite values mean the default) before the tab bar is laid out (in -init… or -viewDidLoad), with no dispatch_after to wait for the animation views; or override its getter in a subclass. Each Lottie view gets it once, when it is added, in the classic, Liquid Glass (normal and selected buttons) and flat design styles.
One tab, or a callback: observe CYLTabBarItemLottieAnimationViewDidAddNotification. It is posted on the main queue after a Lottie view is added; its object is the tab button and tabButton.cyl_lottieAnimationView is the view. The default speed has been applied by then, so a speed set there with -[UIControl cyl_setLottieAnimationSpeed:] is kept. In Liquid Glass a tab has two buttons, so it is posted once for each.
// In a CYLTabBarController subclass
- (void)viewDidLoad {
[superviewDidLoad];
self.lottieAnimationSpeed = 1.5; // every tab
__weak __typeof(self) weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:CYLTabBarItemLottieAnimationViewDidAddNotification object:nil queue:[NSOperationQueuemainQueue] usingBlock:^(NSNotification *note) { UIControl *tabButton = note.object;if (tabButton.cyl_tabBarController == weakSelf && tabButton.cyl_tabBarChildViewControllerIndex == 0) { [tabButton cyl_setLottieAnimationSpeed:2.0]; // the first tab only } }];}
Only takes effect with Lottie integrated (e.g. pod 'CYLTabBarController/Lottie'). A memory warning does not reset the speed: the Lottie views live in the tab buttons, which unloading unselected tabs' pages (#426 above) does not remove; the log of +[CYLTabBarController cyl_simulateMemoryWarning] shows it. Full examples are in the demos: ObjC MainTabBarController.m, Swift Example-Swift/MainTabBarController.swift.
[CN]能否只给中间的 PlusButton 添加 Lottie 动画?是否支持 SVGA 动画?
[EN]Can only the center PlusButton have a Lottie animation? Is SVGA supported?
2. Restructure to RootNavigationController → TabBarController → tab pages and push everything through the outer navigation controller. Developers report this works, but existing projects need their navigation code changed.
3. 完全自定义 TabBar 需要使用私有 API,有审核风险,本库不采用。
3. A fully custom TabBar needs private APIs and risks App Review rejection, so the library does not do this.
[CN]首页 push 后无法右滑返回;侧滑返回时崩溃
[EN]Swipe back stops working after a push from the home page; swipe back crashes
With the navigation bar hidden, the system swipe-back gesture can misbehave. Work around it with the methods in UIViewController+CYLNavigationControllerExtention.h:
// viewWillDisappear: / dealloc: disable swipe back during the transition// viewWillDisappear: / dealloc 中调用:转场过程中禁用侧滑手势
- (void)cyl_disableInteractivePopGestureRecognizer;
// viewDidDisappear: enable it again after the transition// viewDidDisappear: 中调用:转场结束后重新启用
- (void)cyl_enableInteractivePopGestureRecognizer;
中文
English
如果仍然崩溃,请提交 bug 并附上崩溃日志。
If it still crashes, report a bug with the crash log.
[CN]每个 Tab 页面都要单独隐藏导航栏吗?
[EN]Do I have to hide the navigation bar in every tab page?
Each UINavigationController controls its own bar; the library does not hide them. Call [self.navigationController setNavigationBarHidden:YES animated:animated] in a shared base class's -viewWillAppear:, or handle it in -navigationController:willShowViewController:animated: of a UINavigationControllerDelegate.
[CN]页面内容(如 TableView)被 TabBar 遮挡
[EN]The TabBar covers page content such as a table view
In old versions, all TabBarControllers shared global layout data and affected each other. Each TabBar now keeps its own (see #489); upgrade to the latest version.
Both libraries change the TabBar's appearance and behavior. Upgrade both CYLTabBarController and QMUIKit to their latest versions; developers report the conflict is gone after that. If not, report a bug with a demo that reproduces it.
[CN]10. 其他
[EN]10. Other
[CN]iPhone 12 mini 的高度是 780,CYL_IS_IPHONE_X 的判断需要修改吗?
[EN]The iPhone 12 mini is 780pt tall; does CYL_IS_IPHONE_X need changing?
No. The iPhone 12 mini's logical UIScreen size is 375 × 812 (780 comes from its physical pixels), which meets the condition. Also, CYL_IS_IPHONE_X now uses the TabBar's actual visible size.
A tab title that flickers when switching tabs, or turns into the navigation bar title (#258), is also caused by self.title: the page runs viewDidLoad only when first selected, and UIKit copies its self.title into tabBarItem.title. See the FAQ.
中文
English
self.title = @"同城"; 这种方式,如果和 tabBarItemsAttributes 中对应的 title 不一致的时候可能会导致如下现象(不算 bug,但看起来也很奇怪):
If self.title = @"同城"; differs from the corresponding tabBarItemsAttributes title, the following strange-looking behavior may occur (this is not technically a bug):
中文
English
推荐规则如下:
Recommended usage:
self.navigationItem.title = @"同城"; //✅sets navigation bar title.The right way to set the title of the navigation
self.tabBarItem.title = @"同城"; //❌sets tab bar title. Even the `tabBarItem.title` changed, this will be ignored in tabbar.
self.title = @"同城1"; //❌sets both of these. Do not do this‼️‼️ This may cause something strange like this : http://i68.tinypic.com/282l3x4.jpg
This is system behavior, not the tab bar (#719, #680). When an app does not support landscape, the unfolded iPhone Duo held in landscape shows it as a portrait window in the middle of the screen, with black bars on both sides. Checking only Portrait does exactly this.
1. A valid launch screen: UILaunchScreen in Info.plist (iOS 14+), or UILaunchStoryboardName naming a dedicated launch storyboard. Give the name without the .storyboard extension, use no custom classes, and lay it out with Auto Layout for any size. Do not use Main.storyboard as the launch screen.
2. Landscape in Info.plist: UISupportedInterfaceOrientations includes LandscapeLeft and LandscapeRight. The system only picks from these, so code cannot return an orientation missing here.
3. Allow landscape at run time: if you implement application:supportedInterfaceOrientationsForWindow: or supportedInterfaceOrientations, return a mask with landscape on foldable devices.
To keep other iPhones portrait-only, keep landscape in Info.plist, return portrait in code by default, and allow landscape once a hinge is reported (only foldable devices report one). The demo does this; see Example/CYLMainRootViewController.m and Example/ AppDelegate.m: