KAlertController可更改外观的提示

前言:

               从 我们熟悉的UIAlertViewUIActionsheet 在IOS 8 之后,被苹果融合为UIAlertController 。以往的写法一个样式得写一套灵活性较差。ios8以后,UIAlertcontroller 的使用改善了以往的两种提示,增加了灵活性。但是UIalertController 也有自己的弊端。弊端:它样式单一、该类提供的API也没有可以更改的Func 。优点:使用简单方便、苹果的简约风格。但是,这么好的提示,也满足不了我们开发APP的设计工程师的眼睛。为了更好的使用提示,我自己就做了一个,功能简单。有不足的地方还请海涵。

第一:效果

              本框架一共有两个样式(Alert and ActionSheet)。如下:


第二:静态库的介绍


介绍:KAlerVController.h

//

//  KAlertVController.h

//  KUIAlertController

//

//  Created by 周双建 on 16/5/16.

//  Copyright © 2016周双建. All rights reserved.

//


#import <UIKit/UIKit.h>

// base type

typedef NS_ENUM(NSInteger,KAlertType){

    KAlertController= 0,

    KAlertControllerSheet,

};

// func back

typedef  void( ^ Selblock)(UIButton* Action);

@interface KAlertVController : UIView

// 设计三个量

// heart

@property(nonatomic)UILabel * KAlertTitle;

// body

@property(nonatomic)UILabel * KAlertMesage;

// back——view

@property(nonatomic)UIView * KAlertBackView;

// readonly object type

@property(nonatomic)KAlertType  Alerttype;


// make object func

+(KAlertVController*)addtitle:(NSString*)title message:(NSString*)message type:(KAlertType)type;

// you can set textcolor and font  of title

-(void)settitlecolor:(UIColor*)color;

-(void)settitlefont:(UIFont*)font;

// you can set textcolor and font  of title

-(void)setmessagecolor:(UIColor*)color;

-(void)setmessagefont:(UIFont*)font;

// Add event

-(void)addAction:(NSArray*)actionobject action:(Selblock)action;

/***********************************************************************/

// other type

+(KAlertVController*)addAlerSheettitle:(NSString*)title actionsheet:(NSArray*)actionsheet action:(Selblock)action;

@end

第三:使用
              首先,导入ZSJKAlertController 文件到您的工程里面,在您使用的页面导入 该 #import"KAlertVController.h"头文件。即可使用,不用配置任何地方。
第四:该库的使用。
一:Alert 的使用

  // you can setting your alert type in here

        // Alert type used

        KAlertVController * AK = [KAlertVController addtitle:@"Success-Bar" message:@"月落乌啼霜满天,江枫渔火对愁眠。姑苏城外寒山寺,夜半钟声到客船" type:KAlertController];

        AK.KAlertTitle.textColor = [UIColor redColor];

        // set color of alert message

        [AK setmessagecolor:[UIColor magentaColor]];

        // set font of alert title

        [AK settitlefont:[UIFont fontWithName:@"Zapfino" size:20]];

        // set font of alert message

        [AK setmessagefont:[UIFont systemFontOfSize:12]];

        [AK addAction:@[@"离去",@"停泊"] action:^(UIButton *Action) {

            // change backView color

            Action.backgroundColor  = [UIColor redColor];

            // change font of  action title

            [Action setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

            // action  event

            [Action addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];

        }];


  

-(void)Click:(UIButton*)Mybtn{

        // The corresponding event

    if (Mybtn.tag==0) {

        NSLog(@"欢迎下次再来");

        // cancle ( one type)

        for (UIView * TempViewin [UIApplicationsharedApplication].keyWindow.subviews) {

            if ([TempView isMemberOfClass:[KAlertVController class]]) {

                [TempView removeFromSuperview];

            }

        }

    }else{

        // other action event

        NSLog(@"亲这里不是温暖的港湾");

    }

}


      Alert 的类型效果:





二,AlertSheet 的使用

        KAlertVController * AKSheet  = [KAlertVControlleraddAlerSheettitle:@"请选择选择"actionsheet:@[@"相机",@"相册",@"取消"]action:^(UIButton *Action) {

            [Action addTarget:selfaction:@selector(ActionSheetClick:)forControlEvents:UIControlEventTouchUpInside];

        }];


// AlertSheet actionEvent

-(void)ActionSheetClick:(UIButton*)AsBtn{

    if (AsBtn.tag==0) {

        NSLog(@"您选择了相机");

    }else if (AsBtn.tag==1){

        NSLog(@"您选择了相册");

    }else{

        NSLog(@"您取消选择");

        for (UIView * TempViewin [UIApplicationsharedApplication].keyWindow.subviews) {

            if ([TempView isMemberOfClass:[KAlertVController class]]) {

                [TempView removeFromSuperview];

            }

        }

    }

}


  AlertSheet 的样式:



第五:测试demo 的下载地址
http://download.csdn.net/detail/zhoushuangjian511/9548745

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
本库更新,添加提示图片,支持图片提示功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值