简体   繁体   English

您如何使用本机中的 ion-menu 为 ionic 中的侧边菜单制作圆角

[英]How do you make rounded corners for side menu in ionic using ion-menu in native

Hi I have researched everywhere and looked at XCode but haven't figured it out.嗨,我到处研究并查看了 XCode,但还没有弄清楚。 I want to create the venmo style rounded corners for my iOS application, but iOS seems to not obey the sass rules I am setting for it.我想为我的 iOS 应用程序创建 venmo 风格的圆角,但 iOS 似乎不遵守我为其设置的 sass 规则。 The side menu styling is controlled by a div class <div class='menu-inner'>...</div> which is generated from <ion-menu> tag.侧边菜单样式由从<ion-menu>标记生成的 div 类<div class='menu-inner'>...</div>

My sass rule works well on the browser, but I am surprised to find it doesn't work in native production specifically iOS.我的 sass 规则在浏览器上运行良好,但我惊讶地发现它不适用于本机生产,特别是 iOS。 Here is my sass rules.这是我的 sass 规则。

.menu-inner {
  border-radius: 0 1.7rem 1.7rem 0!important;
}

which results in the browser with the desired result.这导致浏览器具有所需的结果。 In chrome inspector在铬检查员

However, in XCode iOS 12.1 iPhone X results in sharp cornered edges.但是,在 XCode iOS 12.1 iPhone X 中会产生尖角边缘。 iPhone X emulator iPhone X 模拟器

How do I make the corners rounded in the native app using ionic 3.如何使用 ionic 3.0 在本机应用程序中使角变圆。

You could do it with shadow parts.你可以用阴影部分来做。 In the component's CSS file you can specify it like :在组件的 CSS 文件中,您可以像这样指定它:

ion-menu::part(container) {
border-radius: 25px;
}

Read more about ShadowParts阅读有关ShadowParts 的更多信息

While this is not the correct solution to this question I did find a creative work around if this is a feature you really want for your project.虽然这不是这个问题的正确解决方案,但我确实找到了一个创造性的工作,如果这是您真正想要的项目功能。 The solution involves simply creating four div boxes and then fixing them to the corners of the <ion-menu> .解决方案包括简单地创建四个 div 框,然后将它们固定到<ion-menu>的角落。

四个div框

Here's the code for this.这是代码。

`<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>
`

And then finally blend them in for the correct look and feel to make it seem as if the corners are rounded.然后最后将它们混合在一起以获得正确的外观和感觉,使其看起来好像角落是圆形的。 For me I swapped red -> #f8f8f8 and blue -> #999 to blend into the background which gave me this.对我来说,我交换了red -> #f8f8f8blue -> #999以融入背景,这给了我这个。 在 iOS 13.1 iPhone 8 Plus 上运行的 Ionic 3 MyApp

Totally solved the problem for me!完全解决了我的问题! However, this is not the way it should be.然而,这不是它应该的方式。 I suspect an override of the border-radius property once ionic compiles to the native platform.我怀疑一旦 ionic 编译到本机平台,就会覆盖 border-radius 属性。

All the best coding!所有最好的编码!

Add this code in to your app.component.ts file it will definately work:将此代码添加到您的 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);
  }

It works here它在这里工作

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);
    });
}

Project environment项目环境

   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

recently I also had to make a similar change, to make the menu corner rounded, after some reading I have found a easy solution,最近我也不得不做一个类似的改变,使菜单角变圆,经过一些阅读我找到了一个简单的解决方案,

Add the below code in the css file where you have used ion-menu在使用 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM