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
The second is a side-bar menu with multiple selection. The example app saves the filter conditions (UserDefaults, the host handles the selection result); the component itself neither reads nor persists business data.
The component supports iOS 15.0 and later. It is not on the CocoaPods trunk: reference a commit of this repository, and pin CYLAnimatedItem (CYLTabBarController's animated icon component, also not on the trunk) by commit the same way. Use the newest commit of master and the CYLTabBarController commit its own Podfiles name:
pod'CollectionViewClassifyMenu',:git=>'https://github.com/ChenYilong/CollectionViewClassifyMenu.git',:commit=>'<CollectionViewClassifyMenu commit>'pod'CYLAnimatedItem',:git=>'https://github.com/ChenYilong/CYLTabBarController.git',:commit=>'<the CYLTabBarController commit in this repository\'s Podfile>'
The .xcworkspace and Podfile.lock are generated by pod install and are not committed to the repository (the same as in CYLTabBarController's .gitignore).
pod install
open CollectionViewClassifyMenu.xcworkspace
cd TagCollectionView
pod install
open TagCollectionView.xcworkspace
快速开始(Swift) / Quick start (Swift)
中文
English
核心库是纯 Swift,公开 API 同时带有 @objc 标注。请在宿主中实现 CYLMenuDataSource,并在菜单使用期间持有它。组件对数据源和代理只做弱引用。宿主提供分区标题和条目标题、可选的图片与互斥项标记,处理选择事件,并决定是否保存以及如何保存。
The core library is pure Swift, and its public API also carries @objc annotations. Implement CYLMenuDataSource in the host and retain it for as long as the menu is in use. The component holds the data source and delegate weakly. The host provides section and item titles, optional image and exclusive-item flags, handles selections, and decides whether and how to persist them.
importCollectionViewClassifyMenu
// self implements CYLMenuDataSource and CYLMenuDelegate.
letmenu=CYLClassifyMenuViewController()menu.menuDataSource=selfmenu.menuDelegate=selfmenu.defaultVisibleRows=2 // Default: 1.
// Present or embed menu as a child view controller.
The required data source methods are numberOfSectionsInMenu(), menuNumberOfItems(inSection:), menuTitle(forSection:) and menuTitleForItem(at:). Set an optional menuHeaderView before loading the view. menuFooterView sits below the tags in the same scroll view (for example the results of the selected tag; call updateMenuLayout() after its content changes), and selectedIndexPath highlights the selected tag (set it from menu(_:didSelectItemAt:); taps do not change it). After changing host data, call reloadMenuData(). The filter controller uses the same protocols; selectedIndexPaths allows the host to save and restore selections. reloadMenuData() resets filter selections to each section's first exclusive item, if one is supplied.
CYLTagView also accepts the same protocols and supports both CYLTagView() and CYLTagView(frame:) (CocoaPods only; Swift Package Manager does not include it yet). See the two demo controllers for complete implementations.
CYLTagListView:可组合的标签菜单 / CYLTagListView: composable tag menu
CYLTagListView is an embeddable tag view: the host provides all data and business logic through CYLMenuDataSource / CYLMenuDelegate, and the component only handles layout, folding and selection state. The two scenarios in this README (the Taobao review filter and the Maimai search categories) are implemented with it in Example/; more usage is in docs/component-architecture.md.
Tag icons are provided by the host (replaces the old "item has an image" callback and the built-in images)
menuImage(forSection:)
Section title icon (CYLClassifyMenuViewController no longer hard-codes images)
menuAccessoryView(forSection:)
Custom view on the right of the section title, such as "Industry: IT & Internet ▾"
menuItemIsEnabled(at:)
Disable a tag, such as "Negative reviews (0)"
menu(_:shouldSelectItemAt:)
Lets the host intercept taps
menu(_:didDeselectItemAt:)
Deselection callback
menu(_:didChangeExpanded:inSection:)
Expand / collapse callback
menu(_:didChangeContentHeight:)
Callback when the content height changes, so an embedding view can adjust its height
menu(_:didChangeSelectedItems:)
Called once after each tap that changes the selection, to refresh the filter results
CYLMenuStyle.foldChevronImage
Image of the bottom fold arrow, rotated 180° when expanded
CYLMenuStyle
Title font and color, icon color (per state), spacing between icon and text, icon size, position offset, layoutCentered, spacing, height, fold text; Dynamic Type
CYLTagAppearance
Per state: background, text color, font, icon color, corner radius (0 means a capsule), border and margin (modeled on CYLBadgeAppearance)
CYLTagButton
A single tag view (a horizontal CYLFlatDesignTabBarButton) and the only "icon + title + animated icon" component; it can be used on its own: init(title:image:) / init(title:image:animationURL:), sized to its content (intrinsicContentSize); the badge badgeValue (nil hides it, an empty string is a red dot, any other text is a capsule) and badgeColor (default systemRed) sit at the top right of the icon (of the title when there is no icon) and VoiceOver reads them as the tag's value; CYLMenuStyle.imagePlacement = .top / .bottom puts the icon above / below the title; height(forTitle:iconSize:style:traitCollection:) measures the height. Android, HarmonyOS and the WeChat Mini Program (cyl-tag-button) have the same API
.none, .footer (the section footer, centered below; Taobao reviews), .headerTrailing (the trailing end of the section header, i.e. the top right; the original classify menu; on the left in right-to-left languages), .headerLeading (the leading end of the section header, before the title) and .tail (the last item among the tags: when folded it is the last visible tag and the hidden tags make room for it; when expanded it follows the last tag; tapping it expands or collapses, which is built in. With an icon only it is a circle with the same outline as the tags; the arrow reuses cyl_fold_chevron from the core bundle and is drawn by CYLTagFoldCell)
CYLMenuFoldControlContent
.iconAndTitle ("More ⌄"), .title ("More") and .icon ("⌄"). When expanded, the styles with an icon keep only the arrow and rotate it 180°, while the text-only style shows "Collapse"
CYLMenuFoldControl properties
title / collapseTitle (default to the localized "More" and "Collapse"), image (defaults to cyl_fold_chevron in the core bundle), color, font, rotatesImageWhenExpanded
title、titleImage、titlePosition、titleStyle
The title above the whole list: .topLeading (top left) or .topCenter (centered). The title is drawn by titleView, which reuses the same view as the tags (CYLTagButton, laid out horizontally) and can show only an icon, only text, or both; titleStyle is a CYLMenuStyle (font, text and icon colors, icon size and position, ...), and the default defaultTitleStyle uses a bold headline font; all public APIs of titleView (such as the animated icon animationURL) are available
The fold control is a borderless CYLTagButton (the same view as the tags) with the icon after the text (CYLMenuStyle.imagePlacement = .trailing). The old foldStyle still works and corresponds to foldControl (.headerButton is the text on the right of the header, .footerChevron is the arrow in the footer). In configuration files the position names are "footer", "headerLeading", "headerTrailing" and "tail" ("headerLeft" / "headerRight" are aliases); the old names bottom, topLeading, topTrailing and inline have been removed (see docs/component-architecture.md).
网格、文字在左图标在右与 More 按钮 / Grid, title-then-icon and the More button
中文
English
搜索页常见的“最近搜索 / 发现”由核心库的接口实现,示例只提供数据与点击事件:
The "recent searches / discover" lists common on search pages are implemented by the core's API; the example only provides the data and the tap events:
When greater than 0, each row has a fixed number of tags of equal width, and text that does not fit is truncated with an ellipsis; gridStyle is a grid look with no background, no border and left-aligned text. Configuration key itemsPerRow
CYLMenuStyle.imagePlacement、contentAlignment
The encapsulated tag button (CYLTagButton) supports the icon before the text (Leading, the default) or after it (Trailing, text on the left and icon on the right); contentAlignment is Center (the default, centered as a whole) or Leading (starting from the left margin: the text first and the icon right after it; a text that is too long is truncated with an ellipsis while the icon always stays visible; with text only, no space is left for an icon). gridStyle is Leading + Trailing. Configuration keys are imagePlacement and contentAlignment. The icon's accessibilityLabel (such as "Hot") is read by VoiceOver as the tag's value
The More button on the right of the section title (three dots, cyl_more in the core bundle, the same as the ellipsis icon used by CYLTabBarController's More tab; replaceable through moreButtonImage / moreButtonColor); the host implements the tap event. Its identifier is CYLTagListMoreButton, VoiceOver reads it as " More actions" by default, and the host can supply a name that matches its action (such as "Shuffle")
Items for which menuItemType(at:) returns CYLMenuItemTypeCreate are shown by the core's CYLTagCreateCell (a subclass of CYLTagListCell): the plus icon cyl_tag_plus in the core bundle, the localized title "New tag" or "New tag: " (CYLMenuNewTag, CYLMenuNewTagNamed; Simplified Chinese, Traditional Chinese and English), a bordered look, and they are never selected. The title returned by the data source is the name to create (an empty string means the host asks for the name), and a tap calls back menu(_:didRequestNewItemWithName:at:).
All the parameters above can be written in a dictionary or a configuration file (foldControl: position, content, title, collapseTitle, image, color, font, rotatesImageWhenExpanded; title, titleImage, titlePosition, titleStyle; an item's type: create), the same way as CYLTabBarController's configuration file initialization. JSON and plist are read directly; formats such as JSON5, YAML, TOML, INI, .properties, XML and Protocol Buffers text are read by CYLTabBarController's CYLTabBarConfigurationParser when CYLTabBarController is linked, and the values are then converted by this project's rules (enum names, colors, sizes and so on can all be written as strings). For examples see Example-Swift/CYLTagEditorExample/CYLTagEditorExample.bundle/<语言>.lproj/fold-styles.{json,plist,yaml,xml}.
Each tag is drawn by CYLTagButton: the icon and title parameters follow CYLTabBarController's CYLFlatDesignTabBarItem exactly, only with a horizontal layout instead of a vertical one; the background, border and corner radius follow CYLBadgeView (CYLBadgeAppearance), with one CYLTagAppearance per state.
menuAnimationURLForItem(at:) (or CYLTagButton.animationURL) can supply Lottie (.json), PAG (.pag), Rive (.riv), SVGA and GIF animation files, played the same way as CYLTabBarController's tab icons: it plays when a tap selects the tag, rests on the last frame while selected, and returns to the first frame when deselected (it does not play when Reduce Motion is on).
CYLTagButton is a subclass of CYLTabBarController's shared animated icon + title component, CYLAnimatedItemView (guide). The pod depends on CYLTabBarController/CYLAnimatedItem only (static images, no tab bar, no animation engine); the app adds the engine of each file type it plays:
cyl_tab_bar={:git=>'https://github.com/ChenYilong/CYLTabBarController.git',:commit=>'<sha>'}pod'CYLTabBarController/CYLAnimatedItemLottieSwift',cyl_tab_bar# or …PAG, …PAGEnterprise, …Rive, …SVGA, …GIF
On Android the library depends on io.github.chenyilong:cyltabbarcontroller-animateditem (no animation library); the app adds Lottie, libpag, rive-android or SVGAPlayer. What a tag shows (CYLAnimatedItemView's rules, inherited):
2. otherwise the static image / selectedImage given to the tag, with the same layout as the image alone (no engine or library, an unknown type, a missing, empty or corrupted file, a failed download), and while a remote file downloads;
3. the component's placeholder (CYLAnimatedItemView.defaultPlaceholderImage, sized like the tag's icon) only when the tag has an animation file and no static image; a tag with a title and no icon never shows one.
Without an engine the playback methods (playAnimation(), restartAnimation(), stopAnimation()) do nothing and animationURL is kept, so the same code animates once an engine subspec is added.
Remote animation files are loaded by the engines, never by the tag: on iOS the Rive and SVGA engines read URLs, while Lottie (Swift, 4.x), PAG and GIF read local files only (a remote URL shows the static image, or the placeholder, at once; a CYLTabBarController TODO); on Android every engine reads URLs.
Options read by the animation library (for example the artboard and state machine of a Rive file) are written in the URL, encoded the same way as CYLTabBarController's CYLTabBarAnimationURLWithOptions(): in code use URL.cylAddingAnimationOptions(_:), in a dictionary or configuration file use CYLTagItemKey.animationOptions ("animationOptions"), or write them directly after the file name ("icons.riv#artboard=CHAT"):
When not selected, the animation rests on the first frame by default (the same as CYLTabBarController's tab icons); a file whose first frame is empty can rest on another frame: menuAnimationRestingProgressForItem(at:), CYLTagButton.animationRestingProgress, or CYLTagItemKey.animationRestingProgress in a dictionary (0...1; for example 1 is the last frame).
Each section can have its own look: menuStyle(forSection:) or CYLTagSectionKey.style in a dictionary (CYLMenuStyleKey keys layered over the list style), for example white-line Rive icons (the icons.riv used by CYLTabBarController's dark tab bar) on dark tags. Colors, fonts, borders, icon colors and the icon-text layout are set per section; the height, spacing and padding always use the list's style. scroll(toSection:animated:) scrolls to a section.
Lottie 2.x looks up the images referenced by the JSON by name, so the example keeps these images in Assets.xcassets/LottieImages (CYLTabBarController's example keeps them in the app root).
The example's "Animation" tab (CYLTagAnimationDemoViewController) uses resources copied from the CYLTabBarController example (the newest commit across all branches): Lottie (with image assets, a placeholder and a green theme), Rive and GIF animation files and the tab bar images (Assets.xcassets/TabBarIcon); the PAG files are downloaded by pod install (including the tab icons tab_home, tab_health, tab_moments and tab_me of CYLTabBarController's Example-PAG). Each section uses one animation library, a tap plays it, and you can play all of them and switch the speed. style.animationSize and style.animationSpeed set the size and the speed.
Backgrounds that ship inside the Rive files: the artboard fill of truck.riv (the red Background) draws a rectangle inside the tag, so its opacity is set to 0 following CYLTableViewPlaceHolder's PR #22 (only this one byte is changed); the sky of house.riv (a purple gradient) and its gray artboard fill are made transparent in the same way (three bytes, changed at the maintainer's decision; the source has no license file and the copyright belongs to the original author), while the ground below the house is part of the picture and is kept. The record and the SHA-256 are in Animations/Rive/README.md.
The same as CYLTabBarController's init(configuration:) and init(configurationFile:) (the keys are in CYLTagListKey, CYLTagSectionKey, CYLTagItemKey, CYLMenuStyleKey, CYLTagAppearanceKey and CYLMenuFoldControlKey):
Values in the file can all be written as strings (colors as "#RRGGBB", images as "system:star", insets as "{t, l, b, r}" or an array, enum names, and so on), and file names are resolved relative to the configuration file or the app resources. JSON and plist are read directly; formats such as YAML and TOML are read by CYLTabBarController's parser when CYLTabBarController is linked. For examples see Example/CYLMenuExample/CYLMenuExample.bundle/Configurations/animated-tags.json and CYLTagConfigurationDemoViewController. The example's PAG files are downloaded by pod install (scripts/fetch-animation-resources.py, with pinned versions and SHA-256 verification, the same as CYLTabBarController). The example's "Style" tab (CYLTagStyleDemoViewController) follows CYLFlatDesignTabBarDemoViewController: the tag preview is at the top, and tapping each row of the list below changes one parameter instantly.
Breaking changes:CYLMenuStyle's flat color, border and padding properties (textColor, itemBackgroundColor, borderColor, cornerRadius, itemHorizontalPadding…) moved to its per-state CYLTagAppearance objects, the title font is now titleFont(for:traitCollection:), and a corner radius of 0 now means a capsule. The old "item has an image" callback was removed; return the image from menuImageForItem(at:) instead. Section icons of CYLClassifyMenuViewController now come from menuImage(forSection:).
标签云:android-tagview 的初始化方式 / Tag cloud, the android-tagview way
中文
English
与 android-tagview 一样:创建列表、设置间距、添加标签,并用 block 监听点击和删除。android-tagview 的每个公开 API 在这里都有对应项,对照表见 docs/android-tagview-api.md。
Like android-tagview: create the list, set its spacing, add tags, and listen to taps and deletions in blocks. Every public API of android-tagview has a counterpart here; the table is in docs/android-tagview-api.md.
lettagListView=CYLTagListView()tagListView.lineSpacing=5 // android-tagview: setLineMargin / app:lineMargin
tagListView.interitemSpacing=3 // setTagMargin / app:tagMargin
tagListView.tagContentInsets=UIEdgeInsets(top:3,left:10,bottom:3,right:10) // textPadding…
tagListView.addTags(withTitles:["Asia","Europe","Africa"])lettag=CYLTag(title:"Tag Text",backgroundColorHex:"#DDDDDD")tag.textColor=.whitetag.highlightedBackgroundColor=UIColor(white:0.33,alpha:1) // layoutColorPress
tag.cornerRadius=20tag.textSize=14tag.borderWidth=1tag.borderColor=.whitetag.isDeletable=true // a "×" after the title
tagListView.addTag(tag)tagListView.tagClickHandler={index,taginprint("click",index,tag.title)}tagListView.tagDeleteHandler={index,taginprint("deleted",index,tag.title)}
Per-side padding: CYLTagAppearance.contentInsets (default {5, 10, 5, 10}; margin is the left and right sides) and CYLMenuStyle.tagContentInsets; in Interface Builder you can set lineSpacing, interitemSpacing and tagContentInsetTop/Left/Bottom/Right.
每个标签可以有自己的字号,行高随之变化:字号较大的标签比同一行的其他标签更高。
Each tag can have its own font size and the row height follows: a tag with larger text is taller than the others in its row.
Every public API of three Android tag libraries has a counterpart here (100 each), and their samples are ported to Swift (the "Style" tab → Android tag library samples). The core draws and handles everything; the samples pass data and style values and handle taps.
Languages and accessibility: the example's text is available in Simplified Chinese, Traditional Chinese and English in CYLMenuExample.bundle; the English is the original text of the three Android samples. The core provides alternative actions for users who cannot long-press, drag or tap an image (VoiceOver, Voice Control, Switch Control): "Move earlier / later" and a long-press action for tags (longPressAccessibilityActionName); the dot of an image tag is one element ("Tag group: ...") that can be moved up / down / left / right and deleted; the image itself is a button; the badge is read as the tag's value (badgeAccessibilityLabel). The text of image tags grows with Dynamic Type; when enlarged the lines get longer, long tags wrap automatically, and tags never overlap.
Search bars: all search bars in the example (the scenario 2 search categories, search history and discover, YY hot searches) use CYLSearchBarView from the sibling repository CYLSearchViewController, pulled in as a commit dependency (CYL_SEARCH in Example/Podfile).
android/ is the Android version: the three Android tag libraries, each transcribed to Kotlin, merged into one library (android/merged/library, package com.cyl.classifymenu) that keeps all their APIs and matches every public API of the iOS library: 893 / 893 (table: docs/android-api.md). The example app (android/merged/example) integrates CYLTabBarController for Android by commit (android/merged/gradle.properties), builds its tab bar from a configuration file, gives each example a tab, and raises the plus button above the bar.
Key details, top to bottom: the tab bar and its raised plus button, the review filter in network mode, the SQL of the menu linkage, the jobs page of the search categories, Rive and GIF tags, recent searches and discover, the tag editor:
Version: 27edb4f (the crops come from commits 047b2ab to 27edb4f, the tab bar from 27edb4f; 047b2ab is the earliest commit and 27edb4f the latest, the same 27edb4f as above); CYLTabBarController for Android 4639a0c
Every screen at full size, and the porting log: docs/android.md; cross-platform rules (the shared database, a look consistent with iOS): docs/cross-platform.md.
Upstream pull requests and issues of the three ported libraries: all 4 pull requests merged and all 90 open issues resolved (score 100, docs/android-upstream.md). AndroidTagView, top to bottom: a long tag starts a new line instead of being shortened; end gravity, wrapped text, elevation, a start icon, a custom delete icon and a tag without one:
Every platform uses the same concepts: the host provides a data source (sections, item titles) and a delegate (taps, selection changes), or passes in a configuration (a dictionary / JSON with the same keys as iOS's CYLTagListKey and friends). Below is the smallest setup of each platform; see its document for more.
The library is in android/merged/library (package com.cyl.classifymenu), and the example app references it with implementation(project(":library")). Implement CYLMenuDataSource, create a CYLTagListView, set the data source and reload. See docs/android.md and docs/android-api.md.
The core library is the HAR module harmony/classifymenu (dependency name @cyl/classifymenu, "@cyl/classifymenu": "file:../classifymenu" in the example). Hold the data source and delegate in a CYLTagListState and show it with the CYLTagListView component. See docs/harmony.md.
import{CYLTagListState,CYLTagListView,CYLMenuDataSource,CYLIndexPath}from'@cyl/classifymenu';classReviewSourceimplementsCYLMenuDataSource{privatetitles: string[]=['All','Positive','With photos'];numberOfSectionsInMenu(): number{return1;}menuNumberOfItemsInSection(section: number): number{returnthis.titles.length;}menuTitleForSection(section: number): string{return'Reviews';}menuTitleForItem(indexPath: CYLIndexPath): string{returnthis.titles[indexPath.item];}}// In a component: @State list: CYLTagListState = new CYLTagListState();// aboutToAppear() { this.list.menuDataSource = new ReviewSource(); this.list.reloadMenuData(); }// build() { CYLTagListView({ tagList: this.list }) }
flutter/cyl_tag_list wraps the native CYLTagListView for Flutter (the Swift pod on iOS, the Kotlin library on Android). configuration is the dictionary of iOS's CYLTagListView(configuration:). iOS needs static linking (use_frameworks! :linkage => :static); see flutter/cyl_tag_list/README.md and docs/cross-platform.md.
react-native/react-native-cyl-tag-list is a Fabric view of CYLTagListView (iOS and Android); configuration is the same configuration dictionary, and the events are onTagTap, onSelectionChange and onContentHeightChange. The iOS CylTagListView.mm / .h are React Native's bridge code and stay Objective-C++ as React Native requires. See react-native/react-native-cyl-tag-list/README.md.
Tags are elements with the "button" trait, and the selected and disabled states are read through selected / notEnabled; section titles carry the header trait; the fold button is read as " More / Collapse", and after expanding or collapsing the focus stays on the fold button. The cells of the old multiple filter and the TagView are read the same way.
Dynamic Type
Fonts scale with the system text size (up to 2x), the tag height grows accordingly, and tags are measured again after a size change.
Bold Text
Tags use bold text, and measuring and drawing use the same font, so nothing is truncated.
Increase Contrast
The tag border uses the text color and is at least 1pt.
Reduce Motion
Expanding and collapsing are not animated.
中文
English
| Voice Control / Switch Control / 全键盘控制 | 每个标签、“+ 新建标签”、折叠按钮和列表标题都是带本地化标签的元素,可用名称点击或依次聚焦。 |
| Voice Control / Switch Control / Full Keyboard Access | Every tag, the "+ New tag" item, the fold button and the list title are elements with localized labels, so they can be tapped by name or focused in turn. |
The views of CYLTagListView carry fixed accessibilityIdentifiers (declared in CYLTagListAccessibility.swift), so tests and tools can find them without coordinates:
The title text (for an icon-only title, the icon's accessibilityLabel; without one it is hidden as decoration), header
Tag
CYLTagListItem
The tag text, button, selected / disabled
"+ New tag"
CYLTagCreateItem
"New tag" / "New tag: ", button (never "selected")
Fold button (including the Inline fold cell that acts as a tag)
CYLTagListFoldControl
" More / Collapse", button
More button
CYLTagListMoreButton
" More actions", button
中文
English
数据源可实现 menuAccessibilityHintForItem(at:)为标签提供朗读提示,如 Swift 示例管理模式下的“轻点两下删除此标签”。
The data source can implement menuAccessibilityHintForItem(at:) to give tags a spoken hint, such as "Double-tap to delete this tag" in the manage mode of the Swift example.
All of the component's resources live in a single bundle, CYLClassifyMenuResources.bundle, which contains the images, the XIBs and CYLClassifyMenu.strings under en.lproj, zh-Hans.lproj and zh-Hant.lproj (the sources are in CollectionViewClassifyMenu/Resources/Localization/). The component picks the .lproj itself, so the host app does not need to declare these languages.
Views created after switching the language use the new language. expandTitle / collapseTitle of CYLMenuStyle default to the values in this bundle and can be overridden by the host. When adding a string, add the same key to all three .strings files (a test checks that the keys match).
示例的界面文案同样只放在一个 bundle:Example/CYLMenuExample/CYLMenuExample.bundle,通过 Swift 函数 CYLExampleLocalizedString 读取,键为中文原文;评价关键词与标签属于示例数据,不翻译。启动参数 -CYLExampleLanguage en 可切换示例与组件的语言。Swift 示例使用函数 CYLTagEditorLocalizedString 读取 CYLTagEditorExample.bundle;CollectionViewClassifyMenu.xcodeproj 的演示 App 使用 Swift 函数 CYLDemoLocalizedString 读取 CYLClassifyMenuDemo.bundle。每一层各有自己的查找宏(或函数)与 bundle,代码中不出现面向用户的中文字面量(含无障碍标签与提示)。
The example's UI text is likewise kept in a single bundle, Example/CYLMenuExample/CYLMenuExample.bundle, read through the Swift function CYLExampleLocalizedString, with the original Chinese text as the key; review keywords and tags are example data and are not translated. The launch argument -CYLExampleLanguage en switches the language of the example and the component. The Swift example reads CYLTagEditorExample.bundle with the function CYLTagEditorLocalizedString; the demo app of CollectionViewClassifyMenu.xcodeproj reads CYLClassifyMenuDemo.bundle with the Swift function CYLDemoLocalizedString. Each layer has its own lookup macro (or function) and bundle, and no user-facing Chinese literals appear in the code (accessibility labels and hints included).
示例工程 / Example projects
中文
English
核心库与所有示例(Example/、Example-Swift/、根目录工程的演示 App、TagCollectionView 演示)及其测试均以 Swift 编写;公开 API 带有 @objc 标注,迁移记录见 docs/Swift-Migration.md。
The core library, all examples (Example/, Example-Swift/, the demo app of the root project, the TagCollectionView demo) and their tests are written in Swift; the public API carries @objc annotations, and the migration log is in docs/Swift-Migration.md.
The category tab bar (scenario 2): tapping the search box on the scenario 2 home page pushes the search page (hidesBottomBarWhenPushed, which hides the root tab bar); the CYLTabBarController embedded in the search page is also at the bottom and switches between "People / Posts / Gossip / Jobs", each tab being a tag page.
The PlusButton in the middle of the root tab bar (CYLExamplePlusButton, CYLTabBarController's CYLPlusButton): tapping it opens plusChildViewController (CYLQueryScenariosViewController), which shows the filter demos grouped by scenario. The PlusButton is registered only on the root tab bar's context (CYLExampleRootTabBarContext); the category tab bar embedded in scenario 2 has no PlusButton.
TabBar 总是位于底部;从 Tab 中 push 的页面隐藏根 TabBar。
A tab bar is always at the bottom; pages pushed from a tab hide the root tab bar.
cd Example
pod install
open CYLMenuExample.xcworkspace
CYLProductViewController previews two rows of keywords on the product page with CYLMenuFoldStyle.truncate; CYLReviewListViewController uses a multiple-selection filter with icons and counts, folded to two rows by default, and the bottom arrow rotates 180° to expand or collapse. Every tap (the tap event is shown) refreshes the list below by all the selected conditions (AND; "All" means no limit). A switch at the top distinguishes two modes: in-memory filtering (CYLMemoryReviewQuery, which matches synchronously within the loaded data) and network filtering (CYLNetworkReviewQuery, which encodes the conditions into a request URL, simulates a delayed server response, shows a loading state and discards stale responses).
Scenario 2: Maimai search categories
CYLSearchHomeViewController pushes CYLSearchCategoryViewController, which provides the search box and the categories (People / Posts / Gossip / Jobs) in a CYLTabBarController at the bottom; tapping a tag fills in the search box; on the "Jobs" page the left side holds the job categories and the right side the keywords, and the host supplies an industry picker button on the right of the section title.
| Query filters (PlusButton) · query parameter settings | Taobao reviews show everything by default; when there are too many conditions the user enters them by multiple selection, which is exactly what the tag list (TagCollectionView) is for. The review filter of scenario 1 adds a third mode, database filtering (CYLDatabaseReviewQuery): the selected conditions generate one SQL statement (rating, with images and follow-up reviews are columns of the reviews table, keywords are rows of the review_keywords table, all combined with AND), which is queried in SQLite, and the status bar shows the SQL and the number of matches. |
| Query filters (PlusButton) · recent searches + discover | CYLSearchDiscoverViewController (pure Swift) follows the search page of a search app: a back button at the top, a search box (its placeholder is the first discover topic), an image search button and a "Search" button; "Recent searches" fold to two rows, the arrow is the last tag (CYLMenuFoldControlPosition.tail), and the trash can on the right clears them; "Discover" has two tags per row (gridStyle(itemsPerRow: 2)) with overflow truncated by an ellipsis, a "Hot" icon after the text of hot topics (menuImageForItem(at:), text on the left and icon on the right), and a More button at the top right that refreshes randomly; at the bottom are "Hold to ask, every question answered ✨" and a microphone button. The data lives per language in CYLMenuExample.bundle/<语言>.lproj/search-discover.json (one file each for Simplified Chinese, Traditional Chinese and English, with the recent searches and 24 discover topics in the same order as the hot topics), and the "Hot" icon is likewise kept per language in that .lproj (Simplified Chinese, Traditional Chinese and English variants of "Hot"); a refresh picks 6 at random; tapping a topic or a recent search fills in the search box and moves it to the front of the recent searches. Accessibility: each tag has the hint "Double-tap to search", the More button is read as "Shuffle" (the core's menuAccessibilityLabelForMoreButton(inSection:)), the hot icon is read as "Hot", icon-only buttons support the Large Content Viewer, border colors follow dark mode and Increase Contrast, searching and listening give spoken feedback, and the image search button gives an explanation instead of doing nothing. |
| Query filters (PlusButton) · menu selection | Ports the classify menu and multiple-choice filter of the original demo (CollectionViewClassifyMenu.xcodeproj): CYLMenuLinkageViewController subclasses the core's CYLClassifyMenuViewController, the button at the top left opens the core's CYLMultipleFilterController, and the data source reuses the original demo's CYLDemoDataSource, CYLDBManager and data.json directly (the project references the original files instead of copying them). The original demo only implemented the filter UI and had no data to filter; now tapping a category tag (single selection, highlighted) or confirming a multiple-choice filter (region, dishes) generates SQL, queries the places table, and shows the conditions, the SQL and the result below the tags (menuFooterView); the selections are saved in the selections table of the database and restored when you come back. |
The database is CYLExampleDatabase (the libsqlite3 that ships with the iOS SDK, with the file in the Caches directory): on every launch the reviews, review_keywords and places tables are regenerated from the data inside the app, while the selections table keeps the conditions each demo last confirmed. All values are bound through ?, and the SQL shown in the UI is for display only.
Example-Swift/ (CYLTagEditorExample) is an example written in pure Swift. It also integrates the core library by local path in its Podfile (pod 'CollectionViewClassifyMenu', :path => '..'), so changes to the core code take effect immediately. It demonstrates the new tag scenario in a chat app's contact "Edit remark → Edit tags" flow:
The "Tags" row shows the selected tags (a read-only CYLTagListView); tapping it presents the tag editor as a sheet.
Edit tags (CYLTagEditorViewController)
"Cancel / Edit tags / Done" at the top; "Done" turns green when there is a selection or a change, and is unavailable while searching; a search box; "Recently used" and "My tags" (the right side of the section title shows "Manage", through menuAccessoryView(forSection:)). Selected tags are green, and the same tag is selected in both sections at once. After the last tag comes "+ New tag"; entering a name creates the tag and selects it.
Search
Typing text (case-insensitive, so "ios" finds "iOS") shows "Search results"; when no tag with that name exists, "+ New tag: ios" appears at the end; tapping it or pressing the keyboard's search key creates and selects the tag, ends the search and scrolls to the new tag.
Manage
After tapping "Manage", tapping a tag in "My tags" deletes it.
The demo data comes from local JSON: CYLTagEditorExample.bundle/<语言>.lproj/tags.json (one file each for Simplified Chinese, Traditional Chinese and English, with the same tags in the same order), parsed by CYLTagData (Codable) and loaded according to the app's current language. The content is meaningful contact tags (family, university classmates, clients, iOS development, book club, Shenzhen, to reply...), plus the "Recently used" tags and the tags initially selected on the edit remark page; edit the file to replace the data.
The second tab, "Fold styles" (CYLFoldStylesViewController), creates various fold controls and title styles from initialization parameters (arrow only at the bottom, text + arrow at the bottom, text only at the bottom, text + arrow at the top right (the original classify menu), arrow only at the top right, text + arrow at the top left, centered title), as well as different title styles (icon + text, icon only, centered text only, a green title, icon after the text); every demo uses the encapsulated title property; it then creates them again from JSON, plist, YAML and XML configuration files; the root tab bar is a CYLTabBarController (at the bottom).
To support this the core library adds: menuItemIsSelectable(at:) (for action items such as "+ New tag": a tap calls back but the item is never selected), menuStyleForItem(at:) (the look of a single tag, such as the bordered "+ New tag") and scrollToItem(at:animated:).
cd Example-Swift
pod install
open CYLTagEditorExample.xcworkspace
中文
English
CI 中 Unit tests (swift) 运行其测试,Example screenshots 同时生成其截图(swift-<页面>.png)。
In CI, Unit tests (swift) runs its tests, and Example screenshots also generates its screenshots (swift-<页面>.png).
The tests of the two examples (Example/CYLMenuExampleTests: 115, Example-Swift/CYLTagEditorExampleTests: 22) are organized around protocols: one test case class and one file per feature, and the capabilities they share are protocols with default implementations in Example-Shared/TestSupport/, compiled into both test targets.
协议
作用
CYLWindowHosting
在 App 的 scene 中用自己的窗口显示页面(show(_:)、showInNavigation(_:)),测试结束时关闭
The core library's private views are read only through CYLTagListProbe (the single place that uses key-value coding), so a rename in the core changes only this one place.
Each test target has only one small base class (CYLMenuExampleTestCase, CYLTagEditorTestCase, responsible for the language and the page to show), and the test data and test doubles are in their own Support/ (CYLMenuFixtures, CYLRecordingMenuDelegate, CYLTabBarInspecting).
Tag button appearance, configuration initialization, VoiceOver
CYLTagStyleDemoTests · CYLAnimatedIconTests
The "Style" and "Animation" pages, CYLTabBarController's animation engines
CYLAndroidSampleTests
The ports of the three Android tag library samples and their core features: container border, alignment, themes, cross, ripple, drag reordering, long press, image tags
CYLSearchBarPlacementTests
The search bar never covers any view at any time: the three pages of categorized search, search discover and hot search, at the default and the largest text size
CYLAndroidSampleAccessibilityTests
English and Traditional Chinese for these examples; accessibility actions that replace long press, drag and tapping an image; how badges are read; Dynamic Type for image tags
CYLTagCloudTests
The android-tagview API: CYLTag, adding and removing tags, deletable tags, pressed color, background image, per-side padding, font size, configuration keys
The Swift example: tag data, tag editing, fold styles, accessibility
scripts/unit-tests.sh example # 115 tests; screenshots in build/test-screenshots/example/
scripts/unit-tests.sh swift # 22 tests; screenshots in build/test-screenshots/swift/
中文
English
Xcode 27(iOS 27 SDK)要求 App 采用 scene 生命周期,否则启动即被 UIKit 终止(测试报 “The test runner crashed before establishing connection”);两个示例和根目录的两个演示 App 因此各有一个 scene delegate(CYLExampleSceneDelegate、CYLTagEditorSceneDelegate、CYLSceneDelegate、CYLTagDemoSceneDelegate;后两个是 scripts/unit-tests.sh menu|tag 的测试宿主),测试窗口也加入 App 的 scene。
Xcode 27 (iOS 27 SDK) requires apps to adopt the scene lifecycle, otherwise UIKit terminates the app at launch (the tests report "The test runner crashed before establishing connection"); the two examples and the two demo apps in the root directory therefore each have a scene delegate (CYLExampleSceneDelegate, CYLTagEditorSceneDelegate, CYLSceneDelegate, CYLTagDemoSceneDelegate; the last two are the test hosts of scripts/unit-tests.sh menu|tag), and the test windows are also added to the app's scene.
Test screenshots (local run: macOS 27.3, Xcode 27.2, iPhone 17 Pro simulator on iOS 26.1; example 80, swift 19, menu 17, tag 6, 122 tests in total, all passing):
单选:替换同组选择
多选
底部箭头:折叠
底部箭头:展开
Single selection: replaces the selection in the same section
Multiple selection
Bottom arrow: folded
Bottom arrow: expanded
分组头按钮:各组独立折叠
行内折叠:折叠
行内折叠:展开
网格:每行两个
Section header button: each section folds independently
Inline fold: folded
Inline fold: expanded
Grid: two per row
宿主图标与分组头附件
240pt 窄屏
样式页:胶囊 + 图标颜色
动效页
Host icons and section header accessory
240pt narrow screen
Style page: capsule + icon color
Animation page
动效页:深色分区(icons.riv)
场景一:商品页预览
场景一:筛选折叠
场景一:筛选展开
Animation page: dark section (icons.riv)
Scenario 1: product page preview
Scenario 1: filter folded
Scenario 1: filter expanded
场景一:好评 + 有图(内存)
场景二:找人
场景二:职位
根 TabBar
Scenario 1: positive reviews + with images (in memory)
The renaming of types and methods (the CYL prefix, Swift naming) is source and runtime incompatible with the old Objective-C names; when integrating the new version update imports, type references and custom XIB / storyboard classes. The full table of old and new names is in docs/Swift-Migration.md ("Swift API changes"). The titleEdgeInsets, imageEdgeInsets and adjustsImageWhenHighlighted that iOS 15 deprecates are no longer used; the button layout is controlled by CYLMenuStyle's imageTitleSpacing and imagePlacement.
发布 / Release
scripts/pod-lint.sh lib
scripts/pod-lint.sh version
scripts/pod-lint.sh bump 0.1.1 # Commit the updated podspec first.
scripts/pod-lint.sh check-tag 0.1.1
# Create and push a matching Git tag, then explicitly:
scripts/pod-lint.sh push
The push command requires a matching tag on origin and an authenticated CocoaPods trunk account. It is not run automatically. The 0.1.0 podspec does not imply that a CocoaPods release or Git tag already exists.