Ionic 4 选项卡:如何创建自定义选项卡
Ionic 4 tabs: How to create custom tabs
我正在尝试设置我的选项卡的样式,使其看起来像 link 中显示的那样。
。
我目前有默认的选项卡样式,但我不知道如何调整它以使其看起来像 linked 图像中显示的那样。社区的任何帮助将不胜感激。
这是我的破解方法,
已在 CHROME Pixel 2 XL 模拟器上测试 这很重要,因为我使用的变量在不同的屏幕比例下看起来绝对不同。我个人使用 411x823,这是 Pixel 2 XL phone 上的屏幕尺寸。您将需要通过 css 媒体查询自行处理所有必要的屏幕尺寸情况,以获得通用解决方案。
初始屏幕:这就是我的开始。我从看起来像默认选项卡离子应用程序的东西开始。就像你拥有的一样。由于我们只处理 html
和 scss
这就是我要展示的内容。
tabs-page.scss
起始文件。
.tabbar {
justify-content: center;
}
.tab-button {
max-width: 200px;
}
::ng-deep ion-icon.icon-button {
background: var(--ion-color-primary-tint)!important;
color: white;
border-radius: 50%!important;
}
tabs-page.html
起始文件。
<ion-tabs>
<ion-tab-bar *ngIf="tabSlot === 'bottom'" slot="bottom">
<ion-tab-button tab="marketplace">
<ion-icon mode="md" name="home"></ion-icon>
<ion-label>Marketplace</ion-label>
</ion-tab-button>
<ion-tab-button tab="friends">
<ion-icon name="contacts"></ion-icon>
<ion-label>Friends</ion-label>
<ion-badge *ngIf="friendCount > 0" color="danger">{{friendCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button (click)="openRequestPage()">
<ion-icon name="add-circle-outline" class="icon-button"></ion-icon>
<ion-label>Request</ion-label>
</ion-tab-button>
<ion-tab-button tab="notifications">
<ion-icon name="notifications"></ion-icon>
<ion-label>Notifications</ion-label>
<ion-badge *ngIf="notificationCount > 0" color="danger">{{notificationCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
End Screen: 这就是您要粗略查找的内容。
最终结果: 这是我从开始时使用的代码最终创建的结果。该解决方案涉及使用 box-shadow
css 属性来提供 "negative" border-radius
样式。然后你需要做的是将你的中心按钮稍微放在你的 tab-bar
上方。我用这个 tutorial 来指导我。此外,查看 box-shadow
的工作原理有助于理清具体细节。
tabs-page.scss
结束文件。
.tabbar {
justify-content: center;
}
.tab-button {
max-width: 200px;
}
::ng-deep ion-icon.icon-button {
background: var(--ion-color-primary-tint)!important;
color: white;
border-radius: 50%!important;
}
:host ::ng-deep .tabs-inner {
position: unset!important;
contain: size style!important;
}
.bottom-tab-bar {
--background: transparent;
--border: 0;
}
ion-tab-button {
--background: beige;
}
.button-center {
--background: transparent!important;
ion-icon {
height: 50px;
width: 50px;
font-size: 75px;
}
}
ion-tab-bar {
&:before {
box-shadow: 0 387px 0 300px beige;
position: absolute;
margin-top: -48px;
padding: 56px;
border-radius: 65%;
content: '';
}
}
.inner-left-btn {
border-radius: 0 39% 0 0; // create the curved style on the left side of the center
}
.inner-right-btn {
border-radius: 39% 0 0 0; // create the curved style on the right side of the center
}
.inner-center-btn {
position: absolute;
left: calc(50% - 35px); // position your button in the center
bottom: 20px; // position your button slightly above the half bezel
font-size: 70px;
--background: transparent;
}
tabs-page.html
结束文件。
<ion-tabs>
<ion-icon name="add-circle-outline" class="icon-button inner-center-btn" (click)="openRequestPage()"></ion-icon>
<ion-tab-bar *ngIf="tabSlot === 'bottom'" slot="bottom" class="bottom-tab-bar">
<ion-tab-button tab="marketplace">
<ion-icon mode="md" name="home"></ion-icon>
<ion-label>Marketplace</ion-label>
</ion-tab-button>
<ion-tab-button tab="friends" class="inner-left-btn">
<ion-icon name="contacts"></ion-icon>
<ion-label>Friends</ion-label>
<ion-badge *ngIf="friendCount > 0" color="danger">{{friendCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button class="button-center">
<div></div>
</ion-tab-button>
<ion-tab-button tab="notifications" class="inner-right-btn">
<ion-icon name="notifications"></ion-icon>
<ion-label>Notifications</ion-label>
<ion-badge *ngIf="notificationCount > 0" color="danger">{{notificationCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
我正在尝试设置我的选项卡的样式,使其看起来像 link 中显示的那样。
我目前有默认的选项卡样式,但我不知道如何调整它以使其看起来像 linked 图像中显示的那样。社区的任何帮助将不胜感激。
这是我的破解方法,
已在 CHROME Pixel 2 XL 模拟器上测试 这很重要,因为我使用的变量在不同的屏幕比例下看起来绝对不同。我个人使用 411x823,这是 Pixel 2 XL phone 上的屏幕尺寸。您将需要通过 css 媒体查询自行处理所有必要的屏幕尺寸情况,以获得通用解决方案。
初始屏幕:这就是我的开始。我从看起来像默认选项卡离子应用程序的东西开始。就像你拥有的一样。由于我们只处理 html
和 scss
这就是我要展示的内容。
tabs-page.scss
起始文件。
.tabbar {
justify-content: center;
}
.tab-button {
max-width: 200px;
}
::ng-deep ion-icon.icon-button {
background: var(--ion-color-primary-tint)!important;
color: white;
border-radius: 50%!important;
}
tabs-page.html
起始文件。
<ion-tabs>
<ion-tab-bar *ngIf="tabSlot === 'bottom'" slot="bottom">
<ion-tab-button tab="marketplace">
<ion-icon mode="md" name="home"></ion-icon>
<ion-label>Marketplace</ion-label>
</ion-tab-button>
<ion-tab-button tab="friends">
<ion-icon name="contacts"></ion-icon>
<ion-label>Friends</ion-label>
<ion-badge *ngIf="friendCount > 0" color="danger">{{friendCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button (click)="openRequestPage()">
<ion-icon name="add-circle-outline" class="icon-button"></ion-icon>
<ion-label>Request</ion-label>
</ion-tab-button>
<ion-tab-button tab="notifications">
<ion-icon name="notifications"></ion-icon>
<ion-label>Notifications</ion-label>
<ion-badge *ngIf="notificationCount > 0" color="danger">{{notificationCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
End Screen: 这就是您要粗略查找的内容。
最终结果: 这是我从开始时使用的代码最终创建的结果。该解决方案涉及使用 box-shadow
css 属性来提供 "negative" border-radius
样式。然后你需要做的是将你的中心按钮稍微放在你的 tab-bar
上方。我用这个 tutorial 来指导我。此外,查看 box-shadow
的工作原理有助于理清具体细节。
tabs-page.scss
结束文件。
.tabbar {
justify-content: center;
}
.tab-button {
max-width: 200px;
}
::ng-deep ion-icon.icon-button {
background: var(--ion-color-primary-tint)!important;
color: white;
border-radius: 50%!important;
}
:host ::ng-deep .tabs-inner {
position: unset!important;
contain: size style!important;
}
.bottom-tab-bar {
--background: transparent;
--border: 0;
}
ion-tab-button {
--background: beige;
}
.button-center {
--background: transparent!important;
ion-icon {
height: 50px;
width: 50px;
font-size: 75px;
}
}
ion-tab-bar {
&:before {
box-shadow: 0 387px 0 300px beige;
position: absolute;
margin-top: -48px;
padding: 56px;
border-radius: 65%;
content: '';
}
}
.inner-left-btn {
border-radius: 0 39% 0 0; // create the curved style on the left side of the center
}
.inner-right-btn {
border-radius: 39% 0 0 0; // create the curved style on the right side of the center
}
.inner-center-btn {
position: absolute;
left: calc(50% - 35px); // position your button in the center
bottom: 20px; // position your button slightly above the half bezel
font-size: 70px;
--background: transparent;
}
tabs-page.html
结束文件。
<ion-tabs>
<ion-icon name="add-circle-outline" class="icon-button inner-center-btn" (click)="openRequestPage()"></ion-icon>
<ion-tab-bar *ngIf="tabSlot === 'bottom'" slot="bottom" class="bottom-tab-bar">
<ion-tab-button tab="marketplace">
<ion-icon mode="md" name="home"></ion-icon>
<ion-label>Marketplace</ion-label>
</ion-tab-button>
<ion-tab-button tab="friends" class="inner-left-btn">
<ion-icon name="contacts"></ion-icon>
<ion-label>Friends</ion-label>
<ion-badge *ngIf="friendCount > 0" color="danger">{{friendCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button class="button-center">
<div></div>
</ion-tab-button>
<ion-tab-button tab="notifications" class="inner-right-btn">
<ion-icon name="notifications"></ion-icon>
<ion-label>Notifications</ion-label>
<ion-badge *ngIf="notificationCount > 0" color="danger">{{notificationCount}}</ion-badge>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>