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 holds the detailed usage that used to be in the README: installation details (CocoaPods, Carthage), the full setup and the PlusButton protocol (code in Swift, type-checked against the framework), and every customization (appearance, tap animations, badges, Dark Mode, localization, orientation, plus button navigation, icon-only items, nested tab bars, cross-platform, Swift, Storyboard, implementation details). The README keeps a Swift quick start and links here.
In addition to CocoaPods and Swift Package Manager, you can integrate the library with Carthage: every release ships a prebuilt XCFramework. Add the following to Cartfile:
Once it is downloaded, drag Carthage/Build/CYLTabBarController.xcframework into the project and set it to Embed & Sign under "Frameworks, Libraries, and Embedded Content".
Note: the first release with an XCFramework is the one after 1.100.0; up to 1.100.0, use github "ChenYilong/CYLTabBarController" ~> 1.100.0. Why prebuilt: this repository holds the Flutter examples' Xcode projects, so Carthage cannot build it from source. The framework contains the core, badges, the flat design style and the resource bundle (localized strings), without Lottie animations (the LottieSwift folder; use CocoaPods or SPM for them); it supports iOS 15.0 and later. On release, scripts/pod-lint.sh bump updates the binary spec CYLTabBarController.json and the Release workflow uploads the zip. See docs/Carthage.md (#384).
Demo project: Example-Swift-Carthage (a copy of Example-Swift-03 integrated with Carthage); see docs/Carthage-Example.md for how to run it and what differs.
[CN]第二步:设置 CYLTabBarController 的两个数组
[EN]Step 2: Configure the view controller and tab bar item attribute arrays
importUIKitimportCYLTabBarControllerfinalclassMainTabBarController:CYLTabBarController{convenienceinit(){
// Optional: only icons, vertically centered (the same as leaving out CYLTabBarItemTitle, which is preferred).
// Initialize self through this initializer; do not create another CYLTabBarController and return it (#404).
self.init(viewControllers:MainTabBarController.makeViewControllers(),tabBarItemsAttributes:MainTabBarController.makeTabBarItemsAttributes(),imageInsets:.zero,titlePositionAdjustment:UIOffset(horizontal:0,vertical:-3.5),context:nil)}
// Not named viewControllers: that would override UITabBarController's own property.
privatestaticfuncmakeViewControllers()->[UIViewController]{[UINavigationController(rootViewController:HomeViewController()),UINavigationController(rootViewController:NearbyViewController())]}privatestaticfuncmakeTabBarItemsAttributes()->[[AnyHashable:Any]]{[[cylTabBarItemTitle:"Home",cylTabBarItemImage:"home_normal", // an image name (String) or a UIImage
cylTabBarItemDarkImage:"home_normal_night", // optional: Dark Mode
cylTabBarItemSelectedImage:"home_highlight"],[cylTabBarItemTitle:"Nearby",cylTabBarItemImage:"fishpond_normal",cylTabBarItemSelectedImage:"fishpond_highlight"]]}}
Pass image names (NSString) when you can: it is the form the library prepares for you and fits most cases. A UIImage is used as it is, for when you want full control of the image (#465).
Rendered as original (AlwaysOriginal), so icons keep the designed colors
Keeps the image's own mode; imageNamed: gives Automatic, which a tab bar tints as a template with the tint color
Dark image
Loaded for you: the asset's Dark appearance, else <name>_dark
Only the image's own Dark appearance, or the image named by CYLTabBarItemDarkImage
Missing image
Transparent placeholder, the layout is kept
Not applicable
中文
English
#465 中未选中的图标变成了灰色剪影,原因是传入的 UIImage 被系统当作模板图着色;改为传图片名后恢复正常。传 UIImage 又希望保持原色,请先调用 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,或在 Asset Catalog 中把 Render As 设为 Original Image。
In #465, unselected icons turned into gray silhouettes because the UIImage passed in was tinted as a template; passing the names fixed it. To keep a UIImage's own colors, call imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal first, or set Render As to Original Image in the asset catalog.
For Dark Mode, add the optional CYLTabBarItemDarkImage / CYLTabBarItemSelectedDarkImage, also NSString or UIImage; the tab switches by itself. Don't pick one image by darkMode when creating the items, as the old sample did: that chooses once, and the tab won't update when the style changes. See Supporting Dark Mode.
不设置 CYLTabBarItemTitle 时,只显示图标并自动居中。
Omit CYLTabBarItemTitle to display and center the icon only.
[EN]Step 3: Set CYLTabBarController as the window's root view controller
// AppDelegate, for an app without scenes (built with an SDK before iOS 27)
funcapplication(_application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{window?.rootViewController=MainTabBarController()returntrue}
An app built with the iOS 27 SDK must use the UIScene life cycle (UIApplicationSceneManifest in Info.plist, and a SceneDelegate), so the root view controller is set in SceneDelegate. A provider is recommended: it is rebuilt after an in-app language change. Full code: Example/SceneDelegate.m; Swift: docs/Swift-Guide.md; SwiftUI: docs/SwiftUI-Integration.md.
Register the subclass by calling [YourClass registerPlusButton] before any CYLTabBarController is created, e.g. in application:didFinishLaunchingWithOptions: (SwiftUI: the App's init).
中文
English
不要在子类的 +load 方法中注册,否则在 iOS 10 上可能发生崩溃。
Do not register it from +load, because this may crash on iOS 10.
// Wrong: do not register from a load-time hook (Objective-C +load). Register in
// application(_:didFinishLaunchingWithOptions:) or the SwiftUI App's init instead:
PlusButtonSubclass.register()
中文
English
协议提供以下可选方法:
The protocol provides the following optional methods:
If the plus button extends beyond the bounds, you may need to remove the default tab bar top shadow by calling the following code from the AppDelegate:
UITabBar.appearance().shadowImage=UIImage()
// iOS 10 and later: use -[CYLTabBarController hideTabBarShadowImageView].
// See the AppDelegate example.
[CN]让 PlusButton 的标题与 Tab 标题对齐
[EN]Align the PlusButton's title with the tab titles
Implement +alignsTitleWithTabBarItemTitles and return YES: the title takes the tab titles' center line, font and colors. Give the plus button a title then: without one the method has no effect, and on Liquid Glass the button covers the whole tab. Do not implement it for a button whose title is drawn on its background image. See docs/PlusButton.md.
[CN]调整 PlusButton 与 TabBarItem 的宽度
[EN]Customize the PlusButton and TabBarItem widths
Customize the TabBar appearance from -application:didFinishLaunchingWithOptions::
// The tab bar items' text attributes and the bar's background image.
funccustomizeInterface(){letitem=UITabBarItem.appearance()item.setTitleTextAttributes([.foregroundColor:UIColor.gray],for:.normal)item.setTitleTextAttributes([.foregroundColor:UIColor.darkGray],for:.selected)UITabBar.appearance().backgroundImage=UIImage(named:"tabbar_background")}funcapplication(_application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{customizeInterface()returntrue}
[CN]捕获 TabBar 点击事件
[EN]Handling TabBar selection events
中文
English
实现以下代理方法即可捕获点击事件。
Implement the following delegate methods to observe selections.
The flat design style (CYLTabBarStyleTypeFlatDesign) calls it too (#610): once for each tap on a tab button or the plus button (with or without a child view controller), with the tapped button as control; a tap on the tab under a plus button with a child view controller passes the plus button.
// CYLTabBarControllerDelegate
// If the plus button has its own action, this method is not called when the plus button is selected.
functabBarController(_tabBarController:CYLTabBarController,didSelectcontrol:UIControl)
中文
English
下面的方法可以捕获跳转前的控制器和即将跳转到的目标控制器。
The following method receives the current and destination view controllers.
When tabs come and go at run time (e.g. the server hides the second or third one), selectedIndex no longer tells which tab it is (#408). Add CYLTabBarItemIdentifier (an NSString, like a tag) to tabBarItemsAttributes, then check and look tabs up by it.
Read it with control.cyl_tabBarItemIdentifier (the tab button or plus button in the delegate methods), viewController.cyl_tabBarItemIdentifier (a view controller in viewControllers and its content view controller), or tabBarController.cyl_selectedTabBarItemIdentifier.
Look up with -cyl_indexOfTabBarItemIdentifier: (NSNotFound when missing), -cyl_viewControllerWithTabBarItemIdentifier:, -cyl_selectTabBarItemWithIdentifier: (selects and returns the view controller) and -cyl_controlWithTabBarItemIdentifier: (tab button or plus button); cyl_tabBarItemIdentifiers lists them all.
Pop / Push:与 …ForClassType: 对应,-cyl_popSelectTabBarChildViewControllerForTabBarItemIdentifier:(及 animated:、completion: 版本)Pop 到当前导航栈底并选中该标识的 Tab,找不到时返回 nil 且不 pop、不切换;-cyl_pushOrPopToViewController:animated:tabBarItemIdentifier:callback: 在 Push 前按标识选中 Tab(completion handler 的 index 被忽略)。
Pop / Push: like …ForClassType:, -cyl_popSelectTabBarChildViewControllerForTabBarItemIdentifier: (and its animated: and completion: versions) pops to the root and selects the tab with that identifier, returning nil and doing nothing when there is none; -cyl_pushOrPopToViewController:animated:tabBarItemIdentifier:callback: selects the tab by identifier before pushing (the completion handler's index is ignored).
Plus button: implement +tabBarItemIdentifier in the CYLPlusButtonSubclassing subclass (e.g. return @"plus"). A tap on it also calls -tabBarController:didSelectControl:, where control.cyl_tabBarItemIdentifier is that identifier; with a plus child view controller, lookups and selection by identifier include it.
Several tab bar controllers: each one (another context, or a pushed one) answers for its own tabs and plus button, and every copy of the plus button carries the identifier. Plus buttons of different contexts can return different identifiers (@"plus" and @"camera" in the demo).
Defaults (when none is set): a tab gets its content view controller's class name (a navigation controller's root; Swift classes without the module), e.g. CYLHomeViewController, with _2, _3... for the next tabs of the same class in one tab bar; a plus button gets its class name, e.g. CYLPlusButtonSubclass, and the plus child view controller shares it. Class names do not change when tabs are added or removed, or with the language. -cyl_defaultTabBarItemIdentifierForViewController: returns a tab's default.
letmessageAttributes:[String:Any]=[CYLTabBarItemTitle:"消息",CYLTabBarItemImage:"message_normal",CYLTabBarItemIdentifier:"message",]
// CYLPlusButtonSubclass.swift
staticfunctabBarItemIdentifier()->String{"plus"}overridefunctabBarController(_tabBarController:CYLTabBarController,didSelectcontrol:UIControl){switchcontrol.cyl_tabBarItemIdentifier{case"plus":break // the plus button
case"message":break // the message tab, wherever it is
default:break}}tabBarController.cyl_selectTabBarItem(withIdentifier:"message")
[CN]点击 TabBarButton 时添加动画
[EN]Adding animations when a TabBar button is tapped
中文
English
Demo 效果:
Demo preview:
中文
English
实现该代理方法即可获取选中的控件,并直接为其添加动画。
Implement this delegate method to access the selected control and animate it.
// AppDelegate
functabBarController(_tabBarController:CYLTabBarController,didSelectcontrol:UIControl){varanimationView:UIView?
// If the plus button has its own action, this method is not called for it.
ifcontrol.cylIsPlusButton(){
// The plus button of this tab bar controller's context.
animationView=CYLPlusButton(forOwner:tabBarController)?.imageView}elseifcontrol.isKind(of:NSClassFromString("UITabBarButton")??UIControl.self){animationView=control.subviews.first{$0.isKind(of:NSClassFromString("UITabBarSwappableImageView")??UIImageView.self)}}guardletanimationViewelse{return}iftabBarController.selectedIndex%2==0{addScaleAnimation(on:animationView)}else{addRotateAnimation(on:animationView)}}
// Scale animation
privatefuncaddScaleAnimation(onview:UIView){letanimation=CAKeyframeAnimation(keyPath:"transform.scale")animation.values=[1.0,1.3,0.9,1.15,0.95,1.02,1.0]animation.duration=1animation.calculationMode=.cubicview.layer.add(animation,forKey:nil)}
// Rotation animation
privatefuncaddRotateAnimation(onview:UIView){UIView.animate(withDuration:0.32,delay:0,options:.curveEaseIn){view.layer.transform=CATransform3DMakeRotation(.pi,0,1,0)}DispatchQueue.main.asyncAfter(deadline:.now()+0.2){UIView.animate(withDuration:0.7,delay:0,usingSpringWithDamping:1,initialSpringVelocity:0.2,options:.curveEaseOut){view.layer.transform=CATransform3DMakeRotation(2*.pi,0,1,0)}}}
[CN]单独使用角标组件 CYLBadgeView
[EN]Using the badge component on its own: CYLBadgeView
The badges are their own subspec, CYLTabBarController/CYLBadgeView (#535). It has no tab bar code, so you can use it alone to add animated badges (red dot, number, text, image, custom view) to any UIView, UIControl (e.g. UIButton), UIBarButtonItem and UITabBarItem.
What Core and CYLBadgeView share lives in the subspec CYLTabBarController/CYLUtils, which both depend on: generic macros, helpers (e.g. -cyl_setHidden:, -cyl_valueForKey:, -cyl_tabButton), +[CYLUtils isLiquidGlassActive], the string table (CYLLocalizedString()) and the resource bundle. CYLBadgeView brings it in automatically.
Core depends on CYLUtils and CYLBadgeView, so pod 'CYLTabBarController', every other subspec, SPM and Carthage include them already; existing Podfiles and code need no change.
importCYLTabBarControlleravatarView.cyl_showBadge() // a red dot
messageButton.cyl_showBadgeValue("99+",animationType:.shake)navigationItem.rightBarButtonItem?.cyl_showBadgeValue("new",animationType:.none)tabBarItem.cyl_showBadgeValue("3",animationType:.bounce) // a system UITabBar too
messageButton.cyl_clearBadge()
// With CYLTabBarController, the plus button can show a badge too, like the tabs (demo: each tap adds 1).
CYLPlusButton(forOwner:tabBarController)?.cyl_showBadgeValue("1",animationType:.bounce)
The API is the same alone or with CYLTabBarController; only the tab bar parts differ. A UIControl gets its badge on the control itself (with CYLTabBarController, a tab button's badge goes on its icon or Lottie view and is mirrored to the Liquid Glass platter). A UITabBarItem gets its badge on the tab icon. VoiceOver texts are the same either way, in CYLUtils' 33 built-in languages.
Carthage only provides the whole of CYLTabBarController, badges included, and has no separate component framework yet. SPM has three more component products, each usable alone (verified with a Swift outside package: each builds on its own and neither builds nor links the tab bar or Lottie; for Objective-C only a compile check was run: clang with the build's module maps compiled @import CYLBadge; and @import CYLTabBarController;, no Objective-C app in Xcode was run): CYLUtilsKit (themes, localization, the resource bundle, the lifecycle library; import CYLUtilsKit), CYLBadge (badges, on top of CYLUtilsKit; import CYLBadge) and CYLAnimatedItem (the animated item component, on top of CYLBadge; import CYLAnimatedItemViews, see docs/Animated-Item.md). Write .product(name: "CYLBadge", package: "CYLTabBarController"). A full example is in step 1 of the README. A plan to depend on one animation engine only is in Swift package: on-demand engines (English, not implemented yet).
Most apps use the same badge everywhere: a red background, white text, one font, the same offset. Set it once with CYLBadgeAppearance instead of on every tab, bar button and view (#425).
Precedence: a value set on an object (e.g. viewController.cyl_badgeBackgroundColor) > the global value > the built-in default. It covers every badge on UIViewController, UITabBarItem, UIBarButtonItem, UIControl and UIView.
Properties: backgroundColor, textColor, font, centerOffset, radius (red dot radius, 4 by default), margin (space around the text, 8 by default), maximumBadgeNumber (99 by default; larger numbers show "99+"), cornerRadius (0 by default, a capsule), borderColor, borderWidth. -reset restores all defaults.
For reused views such as cells, call -[UIView cyl_resetBadgeAppearance] first: it drops the badge properties set for the previous content so they follow the global style again; then set only what differs, instead of setting every property back to a default by hand.
Set it before showing badges. If you change it later, a badge already on screen uses the new colors, font and border the next time it is shown (-cyl_showBadgeValue:animationType:). Setting a color or font to nil on an object goes back to the global value.
Badges always above their host, never clipped: a badge is drawn above everything in its host view. For a control that is not a tab button, such as the plus button, it sits in a transparent view at the top of the control, aligned to the icon, so the control's other content (e.g. an image drawn by a button configuration) cannot cover it. When the host clips (clipsToBounds, masksToBounds or a mask, e.g. a round avatar), it sits in a transparent view right above the host, which keeps its own clipping; the badge follows the host's hidden state and alpha.
Navigation bar / toolbar buttons on iOS 26+ with Liquid Glass: the system draws a bar button's content monochrome in the bar's tint, so a custom badge inside it lost its colors (e.g. a random color became a black dot). With Liquid Glass active, a UIBarButtonItem's badge is now the system UIBarButtonItemBadge, with cyl_badgeBackgroundColor, cyl_badgeTextColor and cyl_badgeFont (global values when unset), so the tint no longer changes its colors. Values and animation types work as before; the animation is added when the system badge view can be found. Before iOS 26, and with UIDesignRequiresCompatibility, nothing changes.
Tab buttons are created when the tab bar is laid out; a badge shown on a tab earlier (e.g. with cyl_showBadge) is dropped. Wrap the tab badge code in -reloadBadgesWithBlock:: it runs right away when the tab buttons exist, otherwise once the tab bar is laid out (#404).
// In a CYLTabBarController subclass: viewDidLoad(), or whenever the badge data changes.
funcreloadBadge(){reloadBadges{tabBarControllerintabBarController.viewControllers?[0].cyl_showBadge()tabBarController.viewControllers?[1].cyl_showBadgeValue("100",animationType:.none)}}
Call it at any time and as often as needed (e.g. in -viewDidLoad and after data changes): each block runs once, none replaces another, and no dispatch_after is needed. -setViewDidLayoutSubViewsBlockInvokeOnce:block: holds a single block, and one set after the tab bar was laid out may never run, so it does not suit badge updates.
Initialize a subclass through [super initWithViewControllers:…] as in Step 2. If -init creates and returns another CYLTabBarController, the app shows that plain instance and the subclass's code, these blocks included, never runs.
2. Naming convention: when you pass @"home_normal" and an image named home_normal_dark exists (home_dark.png for home.png), it is used as the dark image. An image's own Dark appearance wins, so one image never gets two dark sources. Change the suffix with UIImage.cyl_darkImageNameSuffix (e.g. @"-dark"), or set it to nil to turn this off.
3. Name the dark image: add CYLTabBarItemDarkImage / CYLTabBarItemSelectedDarkImage (a name or a UIImage, any name) to tabBarItemsAttributes; it wins over the other two. For a UIImage object, +[UIImage cyl_imageWithImageInfo:darkImageInfo:] builds one from names (rendered as original, like names), and +cyl_lightOrDarkModeImageWithLightImage:darkImage: (same as +cyl_imageWithLightImage:darkImage:, UIImage.cyl_image(withLight:dark:) in Swift) combines any two images.
4. One template image with a dynamic tint color: UIImage.cylImage(withTemplate:tintColor:) (ObjC +cyl_imageWithTemplateImage:tintColor:) paints it once per light and dark into an original-mode pair (no increased-contrast variant). Use it for your own views, such as a tab cover: on iOS 27.2 a template image inside a tab button ignores the view's tintColor and shows white.
Colors: use dynamic colors, such as systemBackgroundColor, the library's cyl_systemBackgroundColor, cyl_labelColor and so on, or give a light and a dark color with +[UIColor cyl_colorWithLightColor:darkColor:] (#552). Images made from a dynamic color with +[UIImage cyl_imageWithColor:size:] (e.g. a shadowImage) switch too.
lethomeAttributes:[AnyHashable:Any]=[cylTabBarItemTitle:"Home",cylTabBarItemImage:"home_normal", // 2. also loads home_normal_dark, if it exists
cylTabBarItemSelectedImage:"home_highlight", // 1. an asset catalog image with a Dark appearance
]letmessageAttributes:[AnyHashable:Any]=[cylTabBarItemTitle:"Messages",cylTabBarItemImage:"message_normal",cylTabBarItemDarkImage:"message_normal_night", // 3. a dark image under any name
]
// 3. or one UIImage holding a light and a dark image
letmessageImage=UIImage.cylImage(withImageInfo:"message_normal",darkImageInfo:"message_normal_night")tabBarController.tabBar.backgroundColor=UIColor.cylColor(withLight:.white,dark:.black)
Prefer names: the library renders them as original and loads their dark images. A UIImage object keeps its rendering mode: an image from imageNamed: is tinted as a template in a tab bar, so call imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal first to show its own colors. See Image names or UIImage objects for the differences (#465).
[CN]使用 CYLTabBarItemDarkImage 指定深色图片
[EN]Naming dark images with CYLTabBarItemDarkImage
键
值
作用
CYLTabBarItemDarkImage
NSString(图片名)或 UIImage
深色模式下的未选中图片,对应 CYLTabBarItemImage
CYLTabBarItemSelectedDarkImage
NSString(图片名)或 UIImage
深色模式下的选中图片,对应 CYLTabBarItemSelectedImage
Key
Value
Purpose
CYLTabBarItemDarkImage
NSString (image name) or UIImage
The unselected image in Dark Mode, for CYLTabBarItemImage
CYLTabBarItemSelectedDarkImage
NSString (image name) or UIImage
The selected image in Dark Mode, for CYLTabBarItemSelectedImage
中文
English
两个键都是可选的,可以只设置其中一个;没有设置的状态仍按 Asset Catalog 的 Dark 外观或 _dark 命名规范查找,都没有时深浅色共用同一张图。
Both keys are optional, and either can be used alone. A state without one still uses the asset's Dark appearance or the _dark naming convention; without those it shows the same image in both styles.
设置后优先于 Asset Catalog 的 Dark 外观和 _dark 命名规范,适合深色图片名称不规则、来自其他 bundle 或在代码中生成(UIImage)的情况。
When set, it wins over the asset's Dark appearance and the _dark naming convention: use it when the dark image has an unrelated name, comes from another bundle, or is made in code (a UIImage).
Works in the classic, Liquid Glass and flat design (CYLTabBarStyleTypeFlatDesign) styles. To change images at runtime, include the keys in the new attributes and call -reloadTabBarItemsWithAttributes:.
The style follows the system setting and any overrideUserInterfaceStyle on a window or view controller, and the tab updates by itself; there is no need to set images again in -traitCollectionDidChange:.
To get the same image as a UIImage object (e.g. for another view), use +[UIImage cyl_imageWithImageInfo:darkImageInfo:], which takes the same values as these keys.
A tab with CYLTabBarLottieURL / CYLTabBarLottieFilePath draws its icon with the Lottie animation, not the images above, and the animation's colors are fixed in its JSON, so they do not follow Dark Mode (#442).
Add CYLTabBarLottieDarkURL (an NSURL) or CYLTabBarLottieDarkFilePath (a file path) for the dark animation. It is shown where the interface style is dark (system setting or overrideUserInterfaceStyle) and swapped in when the style changes, keeping the selected state and progress. Classic, Liquid Glass and flat design styles are supported.
Two ways: a dark file (CYLTabBarLottieDarkURL / CYLTabBarLottieDarkFilePath above, Lottie 2.x and 4.x), or one file plus dark colors (CYLTabBarLottieDarkColors, Lottie 4.x only: CYLTabBarController/LottieSwift, CYLFlatDesignTabBar, SPM). A Lottie file cannot hold both palettes itself: colors in the JSON are fixed values, and dotLottie themes only work in LottieFiles' players, not lottie-ios.
CYLTabBarLottieDarkColors is a keypath -> UIColor dictionary: in Dark Mode the colors are set with Lottie's official value providers (setValueProvider(_:keypath:) with a ColorValueProvider, supported by both rendering engines), and removed in light mode, so the animation shows its own colors again; switching keeps the view and its progress. Keypaths join layer, group and item names with "."; "*" matches one name, "**" any number; print them with logHierarchyKeypaths().
By naming convention: CYLTabBarItemsAttributesAddingLottieFiles() adds ".json" to each item, and CYLTabBarLottieDarkFilePath when "_dark.json" exists (the same suffix as images, UIImage.cyl_darkImageNameSuffix).
Don't check whether the style is dark or light yourself and pick one when you set a color or image: at that moment UITraitCollection.currentTraitCollection is often unspecified, the window scene's and the screen's traits ignore overrideUserInterfaceStyle, and nothing updates when the style changes later. To run code when it changes, compare self.traitCollection in -traitCollectionDidChange:.
If the app does not support Dark Mode (#440), add UIUserInterfaceStyle with the value Light to Info.plist; the whole app then stays light. Or set window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight; (or on the window's root view controller).
Every user-visible text in the library and in all demos is localized into 33 languages: English, Simplified Chinese, Traditional Chinese, Japanese, Korean, French, German, Spanish, Italian, Portuguese (Brazil), Russian, Arabic, Thai, Vietnamese, Indonesian, Turkish, Dutch, Polish, Swedish, Danish, Norwegian Bokmål, Finnish, Czech, Slovak, Hungarian, Romanian, Croatian, Catalan, Malay, Ukrainian, Greek, Hebrew and Hindi.
The translations live in the resource bundle of CYLUtils (which Core depends on), CYLTabBarController.bundle (*.lproj/CYLTabBarController.strings), shipped as is by CocoaPods, SPM and Carthage; no extra import. CYLResourceBundle() returns it, and images can go in it too, e.g. [UIImage imageNamed:@"icon" inBundle:CYLResourceBundle() compatibleWithTraitCollection:nil].
In-app language setting: add the row from -cyl_languageCellForTableView: and call -cyl_presentLanguagePicker on tap (English, Chinese, Hindi, Spanish, Arabic with flag and own name, plus "Follow system"). Its subtitle is always in the device language, so it stays readable after any switch. Set the root with [window cyl_setRootViewControllerProvider:^{ … }] instead of rootViewController: the screen is rebuilt in the new language at once, and right-to-left languages such as Arabic flip the layout.
VoiceOver: switching the language also sets the app's accessibilityLanguage, so VoiceOver uses a matching voice. Badges are read ("Messages, 3 new messages", "New content") even though the badge label sits inside a tab button or cell; the placeholder tab under the plus button reads as the plus button; an icon-only plus button reads as its title or "Plus button".
All text uses one language: the one the app itself is displayed in ([NSBundle mainBundle].preferredLocalizations), matched to the closest translation, else English. So the library never shows a language the app doesn't. To follow the device language, declare CFBundleLocalizations in Info.plist (the demos do).
角标值 @"new" / @"NEW" 仍按原值传入,显示时自动翻译。
Badge values @"new" / @"NEW" are still passed as is, and are translated when shown.
Texts set in a xib or storyboard: call [self.view cyl_localizeTexts] in -viewDidLoad; it translates every UILabel, UIButton title and UITextField placeholder in it, so the xib needs no per-language copy.
To add a text, add "original" = "translation"; to each Resources/<language>.lproj/CYLTabBarController.strings. Without a translation the original text is shown.
Android: CYLLocalization.language = "ar" (null follows the device) is CYLSetLocalizationLanguage() for the library's own texts (badge and plus button accessibility texts, new / NEW badges); those texts are resources generated from the iOS string tables (scripts/android-library-strings.py, run it after changing a .lproj). A right-to-left language mirrors the tab bar, the first tab on the right (CYLTabBar.cyl_isRightToLeftLayout). React Native / Flutter: the component's language prop (see Cross-platform components); the examples' language row works as the Objective-C example's, with translations generated from the library's string tables by scripts/sync-example-shared.py.
[CN]横竖屏适配
[EN]Supporting portrait and landscape orientations
Each TabBar keeps its own item width: tabBar.cyl_tabBarItemWidth (likewise cyl_tabbarItemsCount, cyl_plusButtonIndex, cyl_plusButtonWidth). They do not affect each other with several TabBarControllers, and are updated whenever the width changes. The CYLTabBarItemWidth extern in CYLTabBarController.h holds what was written last and still works.
privatevartabBarItemWidthObserver:NSObjectProtocol?funcupdateTabBarCustomizationWhenTabBarItemWidthDidUpdate(){tabBarItemWidthObserver=NotificationCenter.default.addObserver(forName:NSNotification.Name(cylTabBarItemWidthDidChangeNotification),object:nil,queue:.main){[weakself]_inself?.tabBarItemWidthDidUpdate()}}privatefunctabBarItemWidthDidUpdate(){guardlettabBarController=cylTabBarControllerelse{return}
// The selection indicator is as wide as one tab, in portrait and in landscape.
letsize=CGSize(width:cyl_tabBar?.cyl_tabBarItemWidth??0,height:tabBarController.tabBar.bounds.height)tabBarController.tabBar.selectionIndicatorImage=UIGraphicsImageRenderer(size:size).image{contextinUIColor.yellow.setFill()context.fill(CGRect(origin:.zero,size:size))}}
[CN]访问初始化好的 CYLTabBarController 对象
[EN]Accessing the initialized CYLTabBarController instance
CYLTabBarController.h adds -cyl_tabBarController to NSObject.
因此可以在任意对象中用一行代码访问已初始化的 CYLTabBarController。
It provides one-line access to the initialized CYLTabBarController, similar to retrieving a shared instance.
中文
English
接口如下:
The interface is:
// On any object: for a view controller, the nearest ancestor that is a tab bar controller; otherwise the
// root view controller of the app's key window when it is a tab bar controller.
extensionNSObject{varcylTabBarController:CYLTabBarController?{get}}
titlePositionAdjustment can also be changed at runtime (tabBarController.titlePositionAdjustment = UIOffsetMake(0, -3);): the tabs already added update right away, on every tab bar style. On iOS 13+, when tabBar.standardAppearance (UITabBarAppearance) is set, the offset is written into the appearance too, so it no longer has no effect (#475). The "Title offset" row in the demo's settings section shows it.
中文
English
注意:这两个属性会应用于所有 TabBarItem,并优先于自动居中逻辑。
These properties apply to every TabBarItem and take precedence over the automatic centering logic.
Several PlusButtons can be registered at the same time, one per +tabBarContext. Each TabBarController uses the one whose context equals its own context, and they do not affect each other. A PlusButton is bound to the CYLTabBarController; its TabBar finds it through the controller.
TabBarControllers that share a context each get their own PlusButton: the first uses the registered instance, the others new instances from the same class's +plusButton / +plusChildViewController (so these should return a new instance on every call).
Read the PlusButton and the child view controller of a context with +[CYLPlusButton plusButtonForTabBarContext:] and +[CYLPlusButton plusChildViewControllerForTabBarContext:]. CYLExternPlusButton and CYLPlusChildViewController point at the one registered last.
The demo has two PlusButtons (CYLPlusButtonSubclass, and CYLSecondPlusButtonSubclass, which inherits from it and only changes the icon, the title and the context). Switching the style from the PlusButton, or pushing another TabBarController from a table cell, shows the other PlusButton.
react-native-cyltabbar and flutter_cyltabbar in CrossPlatform/ provide a native tab bar component; iOS and Android share the keys of one configuration file, and JS / Dart draws the pages. Run an example first: see React Native integration and Flutter integration; how it works, and CYLTabBarHostView in a native app: the overview.
The PAG and Rive animated-icon demos each have a React Native and a Flutter version, with the same tab bar as Example-PAG and Example-Rive; animations in a page play through CYLAnimationView. See Animated-icon demos.
WeChat Mini Program: the cyl-tab-bar component in CrossPlatform/wechat-miniprogram-cyltabbar draws the tab bar in mini program code and reads the same configuration keys (tabs, the raised plus button and its page, badges, skins and Dark Mode, the three styles, tap animations, login-required tabs); its example reads the shared Example-Shared/Configurations. Lottie tab icons come from its sub-dependency cyl-lottie-miniprogram (our fork of lottie-miniprogram), PAG icons from cyl-pag-miniprogram and Rive icons from cyl-rive-miniprogram. Key score 100 / 100, see WeChat Mini Program. Below, top to bottom: Lottie icons, badges on Lottie icons, the dark skin with tinted icons, the christmas skin with Liquid Glass (WeChat DevTools 2.02.2609250 simulator, iPhone 12/13 Pro, base library 3.18.0, macOS 27.3, commit 69ae5b1, 2026-11-13).
WeChat Mini Program: Liquid Glass: CYLTabBarItemStyle (flat, liquidGlass) is shared by the bar and its items; the Liquid Glass lens has two looks, CYLGlassLensStyle: regular (the default "liquid", nearly opaque, the same on any bar) and skeuomorphic ("skeuomorphic liquid", see-through, like real glass); the plus button's title sits on the line of the tab titles by default. Below, top to bottom: Liquid Glass regular, skeuomorphic, the plus title aligned (default style, Liquid Glass) (WeChat DevTools simulator, iPhone, base library 3.17.6, macOS 27.3, after commit 91236d5, 2026-11-13). See WeChat Mini Program.
WeChat Mini Program: feed taps as on iOS: the feeds of Message, Discover and Me act on tap as in the iOS example. Below (WeChat Mini Program, DevTools on Windows 11, simulator iPhone 12/13 Pro, base library 3.17.6, on top of ef5afc3, 2026-11-15), top to bottom: Message row 1 pushes a tab bar of a new context whose plus button has a tappable X (#202); the Discover details page (orange, pop gesture off); the Me feed with Me selected. See WeChat Mini Program.
WeChat Mini Program: the Objective-C example’s tabs and launch: Home / Refresh, Nearby, Post, Messages, Me, the ObjC images and red / green titles, Liquid Glass; 1.5 s after launch the badges (purple 8, 99+, NEW, plus button 1) and the cover over Home; a tap that selects a tab turns its badge into a dot of its color; Messages and Me need login. Below (WeChat Mini Program, DevTools on Windows 11, simulator iPhone 12/13 Pro, base library 3.17.6, on top of 4e2e327, 2026-11-15), top to bottom: after launch; Nearby tapped; Messages tapped while logged out. Progress: ObjC example parity.
WeChat Mini Program: the Home navigation bar and the 17 skins: as the Objective-C example, "Flat Design" (a breathing dot) on the left of the Home navigation bar, "Skin" and "Liquid Glass" (a shaking dot) on the right; the first and last replace the bar with a new one in that style, "Skin" opens the menu of the 17 skins and "Follow the system Dark Mode" (holiday icons, network icons, colors). Below (WeChat Mini Program, DevTools on Windows 11, simulator iPhone 12/13 Pro, base library 3.17.6, on top of b850f51, 2026-11-15), left to right: after launch; the skin menu; Christmas; FlatDesign in the network skin. Progress: ObjC example parity.
WeChat Mini Program: the Home rows with the Objective-C values: title offset 0 / -4 / 4, the four standardAppearance themes, the four scroll behaviors, the FlatDesign item background, tabs updated in place ("Purchased courses", network / local / GIF icons, "★ " titles, with checkmarks, tap again to restore), selectedIndex wrapping. Below (WeChat Mini Program, DevTools on Windows 11, simulator iPhone 12/13 Pro, base library 3.17.6, on top of a9b1278, 2026-11-15), left to right: Dark + local icons; Centered capsule + network icons + "★ " titles; FlatDesign + Green line + item background. Progress: ObjC example parity.
WeChat Mini Program: previous / next arrows, the plus button's touchable area, replaced neighboring tabs, long press and double tap timings: as the Objective-C example, ◀︎ ▶︎ call cyl_switchToAdjacentTab (no wrapping, YES / NO shown); a switch shows the plus button's touchable area in red and a slider multiplies it 1–3; Nearby becomes "Replaced page B"; the long press and double tap timings cycle through three presets. Below (WeChat Mini Program, DevTools on Windows 11, simulator iPhone 12/13 Pro, base library 3.17.6, on top of 5d86b75, 2026-11-15), left: the 1.8x touchable area and the "Replaced page B" tab; right: ▶︎ opened Replaced page B. Progress: ObjC example parity.
[CN]在 Swift 项目中使用 CYLTabBarController
[EN]Using CYLTabBarController in a Swift project
中文
English
仓库提供了 Swift Demo,目录为 Example-Swift。
The repository includes a Swift demo in Example-Swift.
完整的中英文 Swift 使用指南(import 报错排查、初始化、PlusButton、代理、角标、Lottie、深色模式等 API 示例):docs/Swift-Guide.md。
A full bilingual Swift guide (fixing import errors, initializers, PlusButton, delegates, badges, Lottie, Dark Mode and more, with code): docs/Swift-Guide.md.
Integrating it in a SwiftUI app (UIViewControllerRepresentable, UIHostingController, driving the tab bar from SwiftUI): docs/SwiftUI-Integration.md, example in Example-SwiftUI.
中文
English
在 Swift 项目中作为静态库使用:
To use the library as a static library in a Swift project:
中文
English
使用 CocoaPods:
With CocoaPods:
platform:ios,'15.0'# Uncomment the next line when you want all Pods as static framework# use_modular_headers!pod'CYLTabBarController','~> 1.100.0',:modular_headers=>true