此页面介绍如何在应用程序中使用 Ionic 的 Segment 和 Tab 组件来组织内容和导航。Segments 提供水平控件,用于在不同视图之间进行选择,而 Tabs 则将内容组织到可独立导航的部分中。
有关通用导航组件的更多信息,请参阅 导航组件。
Segments 和 Tabs 在 Ionic UI 生态系统中扮演着不同但互补的角色。
ion-segment)提供了一个水平选择控件,允许用户在多个选项之间进行选择,通常用于过滤内容或在同一页面内切换视图。来源:core/src/components/segment/segment.tsx core/src/components/segment-button/segment-button.tsx
The ion-segment component is a horizontal control that provides a way to select between multiple options. It consists of multiple ion-segment-button elements.
Sources: core/src/components/segment/test/basic/index.html24-36
| 属性 | 类型 | 默认 | 描述 |
|---|---|---|---|
value | 字符串 | - | The value of the selected segment button |
disabled | 布尔值 | false | Whether user interaction is disabled |
scrollable | 布尔值 | false | Whether segment buttons will overflow and can be scrolled |
swipeGesture | 布尔值 | true | Whether users can swipe between segment buttons |
selectOnFocus | 布尔值 | false | Whether keyboard navigation selects buttons (vs just focus) |
color | 字符串 | - | The color to use from your application's color palette |
Sources: core/src/components/segment/segment.tsx49-133
| 事件 | 描述 |
|---|---|
ionChange | Emitted when the value property has changed from user interaction |
ionSelect | Emitted when the value of the segment changes (internal event) |
Sources: core/src/components/segment/segment.tsx139-154
The ion-segment-button is a child component of ion-segment that represents a selectable option.
Sources: core/src/components/segment-button/segment-button.tsx core/src/components/segment-button/segment-button.scss234-261
| 属性 | 类型 | 默认 | 描述 |
|---|---|---|---|
value | 字符串 | auto-generated | The value of the segment button |
disabled | 布尔值 | false | Whether the segment button is disabled |
layout | 字符串 | "icon-top" | Layout for icon and label placement |
contentId | 字符串 | - | The ID of the segment content to display when selected |
类型 | 字符串 | "button" | The type of the underlying button element |
Sources: core/src/components/segment-button/segment-button.tsx40-63
Segment buttons support different layouts for positioning icons and labels
icon-top: Icon above the label (default)icon-start: Icon to the left of the labelicon-end: Icon to the right of the labelicon-bottom: Icon below the labelicon-hide: No icon, only labellabel-hide: No label, only iconSources: core/src/components/segment-button/segment-button.scss234-261 core/src/components/segment-button/segment-button.ios.scss7-47 core/src/components/segment-button/segment-button.md.scss7-26
Segments can control content views using the contentId attribute to connect segment buttons with specific content.
Sources: core/src/components/segment/segment.tsx369-377 core/src/components/segment/segment.tsx420-435
ion-segment-button has an optional contentId propertySources: core/src/components/segment/segment.tsx420-435
For segments with many options, you can enable horizontal scrolling
The scrollable property enables
Sources: core/src/components/segment/test/basic/index.html39-58 core/src/components/segment/segment.tsx437-499
Segments support Ionic's color system and custom CSS properties for extensive customization.
Segment buttons expose many CSS variables for customization
| CSS 属性 | 描述 |
|---|---|
--background | Background of the segment button |
--background-checked | Background of the checked segment button |
--color | Color of the segment button |
--color-checked | Color of the checked segment button |
--indicator-color | Color of the indicator for the checked segment button |
--indicator-height | Height of the indicator for the checked segment button |
--border-radius | Radius of the segment button border |
Sources: core/src/components/segment-button/segment-button.scss7-44 core/src/components/segment-button/segment-button.ios.scss7-47 core/src/components/segment-button/segment-button.md.scss7-26
Segments adapt to both iOS and Material Design platforms
来源: core/src/components/segment/segment.ios.scss core/src/components/segment/segment.md.scss core/src/components/segment-button/segment-button.ios.scss core/src/components/segment-button/segment-button.md.scss
虽然 Segment 可以独立工作,但它们通常与基于标签页的导航模式结合使用
来源: core/src/components/segment/segment.tsx368-377
Segment 支持手势交互
可以通过 `swipeGesture` 属性禁用手势支持,以备不时之需。
来源: core/src/components/segment/segment.tsx79-84 core/src/components/segment/segment.tsx209-228 core/src/components/segment/segment.tsx230-254
Segments 实现了完善的可访问性功能
来源: core/src/components/segment/segment.tsx707-722 core/src/components/segment-button/segment-button.tsx183-197 core/src/components/segment/segment.tsx659-702
来源: core/src/components/segment/test/basic/index.html core/src/components/segment/test/custom/index.html
刷新此 Wiki
最后索引时间2025 年 4 月 18 日(b0d88e)