IONIC中 AlertController和 ActionSheetController的自定义样式

AlertController

  先看对比效果

          

          

          

 实现

html

<!--
  Generated template for the AutoCssPage page.

  See http://ionicframework.com/docs/components/#navigation for more info on
  Ionic pages and navigation.
-->
<ion-header>
  <ion-navbar>
    <ion-title>Auto CSS</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>

  <ion-grid>
    <ion-row>
      <ion-col>
        <button ion-button (click)="ShowAlertController()"> AlertController </button>
      </ion-col>
    </ion-row>

    <ion-row>
        <ion-col>
          <button ion-button (click)="ShowActionSheetController()"> ActionSheetController </button>
        </ion-col>
      </ion-row>

  </ion-grid>

</ion-content>

css

  ion-row{
        ion-col{
            button{
                width: 100%;            
                border-radius: 5px;
            }
        }
    }     

ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController,ActionSheetController  } from 'ionic-angular';

/**
 * Generated class for the AutoCssPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-auto-css',
  templateUrl: 'auto-css.html',
})
export class AutoCssPage {

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public alertCtrl: AlertController,
    public actionSheetCtrl: ActionSheetController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AutoCssPage');
  }

  ShowAlertController() {
    let confirm = this.alertCtrl.create({
      cssClass: 'twoBtn',
      message: '你确定删除?',
      buttons: [{
        text: '取消',
        handler: () => {
          console.log('Disagree clicked');      
        }
      },
      {
        text: '确定',
        handler: () => {
          this.OneBtn();
          console.log('Agree clicked');
        }
      }
      ]
    });
    confirm.present();
  }

  OneBtn() {
    let alert = this.alertCtrl.create({
      cssClass: "oneBtn",
      message: "删除成功",
      buttons: [{
        text: '确定',
        handler: () => {
          console.log('Ok');
        }
      }]
    });
    alert.present()
  }

  ShowActionSheetController(){
    let actionSheet = this.actionSheetCtrl.create({
      title: 'Select your function',
      cssClass:'ascCss',
      buttons: [
        {
          text: 'Take Photo',
          icon: 'ios-camera-outline',
          role: 'TakePhoto',
          handler: () => {
            console.log('Take Photo clicked');      
          }
        }, {
          text: 'Photo Library',
          icon: 'ios-image-outline',
          role: 'PhotoLibrary',
          handler: () => {
            console.log('Photo Library clicked');        
          }
        }, {
          text: 'Cancel',          
          role: 'cancel',         
          handler: () => {
            console.log('Cancel clicked');
          }
        }
      ]
    });

   actionSheet.present();   
  }

}

app.css

// http://ionicframework.com/docs/theming/


// App Global Sass
// --------------------------------------------------
// Put style rules here that you want to apply globally. These
// styles are for the entire app and not just one component.
// Additionally, this file can be also used as an entry point
// to import other Sass files to be included in the output CSS.
//
// Shared Sass variables, which can be used to adjust Ionic's
// default Sass variables, belong in "theme/variables.scss".
//
// To declare rules for a specific mode, create a child rule
// for the .md, .ios, or .wp mode classes. The mode class is
// automatically applied to the <body> element in the app.

 //单个按钮
.oneBtn{
   
    .alert-wrapper {
        border-radius: 10px;
      }
  
  .alert-title {
    font-size: 1.8rem;
    text-align: center;
    margin-top: -10px;
  }
  
   .alert-button-group {
      padding: 0;
      border-top: 1px solid #e1dce6;
      justify-content: center;
    }
  
   .alert-message {
      max-height: 240px;
      font-size: 1.4rem;
      text-align:center;
    }
  
  .alert-button {
    width:100%;
    margin:0;
    .button-inner {
      justify-content: center;
    }
  }

}

//两个按钮
.twoBtn{
   
    .alert-wrapper {
        border-radius: 10px;
      }
  
  .alert-title {
    font-size: 1.8rem;
    text-align: center;
    margin-top: -10px;
  }
  
   .alert-button-group {
      padding: 0;
      border-top: 1px solid #e1dce6;
      justify-content: center;
    }
  
   .alert-message {
      max-height: 240px;
      font-size: 1.4rem;
      text-align:center;
    }
  
  .alert-button {
    width: 50%;
    border-left: 1px solid #e1dce6;
    margin:0;
    .button-inner {
      justify-content: center;
    }
  }
      
}


.ascCss {
    .action-sheet-group {
      width: 98%;
      margin-left: auto;
      margin-right: auto;
      border-radius: 10px;
      margin-bottom: 5px;
  
      .action-sheet-title {
        font-size: 1.6rem;
        color: #000;
        background: #fefef9;
        text-align: center;
      }
  
      .disable-hover {
        border-top: 1px solid #e1dce6;
  
        .button-inner {
          .icon {
            color:aqua;
          }
        }
      }
  
      .action-sheet-cancel {
        margin-bottom: 0px;
  
        .button-inner {
          justify-content: center;
        }
      }
    }
  
    .action-sheet-group:last-child {
      padding-bottom: 0;
    }
  }   

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值