[英]How do you make rounded corners for side menu in ionic using ion-menu in native
嗨,我到处研究并查看了 XCode,但还没有弄清楚。 我想为我的 iOS 应用程序创建 venmo 风格的圆角,但 iOS 似乎不遵守我为其设置的 sass 规则。 侧边菜单样式由从<ion-menu>
标记生成的 div 类<div class='menu-inner'>...</div>
。
我的 sass 规则在浏览器上运行良好,但我惊讶地发现它不适用于本机生产,特别是 iOS。 这是我的 sass 规则。
.menu-inner {
border-radius: 0 1.7rem 1.7rem 0!important;
}
这导致浏览器具有所需的结果。 在铬检查员
但是,在 XCode iOS 12.1 iPhone X 中会产生尖角边缘。 iPhone X 模拟器
如何使用 ionic 3.0 在本机应用程序中使角变圆。
你可以用阴影部分来做。 在组件的 CSS 文件中,您可以像这样指定它:
ion-menu::part(container) {
border-radius: 25px;
}
阅读有关ShadowParts 的更多信息
虽然这不是这个问题的正确解决方案,但我确实找到了一个创造性的工作,如果这是您真正想要的项目功能。 解决方案包括简单地创建四个 div 框,然后将它们固定到<ion-menu>
的角落。
这是代码。
`<ion-menu [content]="content" type="overlay">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
<div style="background-color: blue;height: 10px;width: 10px;position: fixed;right: -1px;
top: 0;"></div>
<div style="background-color: red;border-radius: 0 10px 0 0;height: 10px;width: 12px;position: fixed;right: 0;
top: 0;"></div>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
<div style="background-color: blue;height: 10px;width: 10px;position: fixed;right: -1px;
bottom: 0;"></div>
<div style="background-color: red;border-radius: 0 0 10px 0;height: 10px;width: 12px;position: fixed;right: 0;
bottom: 0;"></div>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
`
然后最后将它们混合在一起以获得正确的外观和感觉,使其看起来好像角落是圆形的。 对我来说,我交换了red -> #f8f8f8
和blue -> #999
以融入背景,这给了我这个。
完全解决了我的问题! 然而,这不是它应该的方式。 我怀疑一旦 ionic 编译到本机平台,就会覆盖 border-radius 属性。
所有最好的编码!
将此代码添加到您的 app.component.ts 文件中,它肯定会起作用:
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.menuRadius(); // call menuRadius method
});
}
menuRadius() {
setTimeout(() => {
document.querySelector('ion-menu').shadowRoot.querySelector('.menu-inner').setAttribute('style', 'border-radius:0px 30px 0px 0px');
}, 2000);
}
它在这里工作
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
setTimeout(() => {
document.querySelector('ion-menu').shadowRoot.querySelector('.menu-inner').setAttribute('style', 'border-radius:0px 60px 0px 0px');
}, 2000);
});
}
项目环境
Ionic CLI : 5.4.6 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.11.5
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.1.1
最近我也不得不做一个类似的改变,使菜单角变圆,经过一些阅读我找到了一个简单的解决方案,
在使用 ion-menu 的 css 文件中添加以下代码
ion-menu::part(container) {
border-radius: 0 70px 0 0;
}
This has to do with the Shadow dom.
Follow below link for more info
https://ionicframework.com/blog/customize-your-ionic-framework-app-with-css-shadow-parts/?_gl=1*1wk5td8*_ga*NDA3OTM3NDc2LjE2MTAzNjA2Nzk.*_ga_REH9TJF6KF*MTYyMjY2OTIwMC4xMTMuMS4xNjIyNjY5MzAwLjA.
Here is a snapshot of menu after above css implementation.
[1]: https://i.stack.imgur.com/T2xsu.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.