Coder Social home page Coder Social logo

gu2890961 / gjalertcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gjgroup/gjalertcontroller

0.0 1.0 0.0 142 KB

在程序中使用UIAlertController而不用关心低版本兼容的问题

License: MIT License

Objective-C 72.08% Ruby 3.37% Shell 24.55%

gjalertcontroller's Introduction

GJAlertController

UIAlertController是一个在iOS8才被加入的类,在低于iOS8版本的设备上无法使用,此库可让使用者在低版本中也可以使用UIAlertController。

也就是说,你在开发的时候尽管使用UIAlertController,就当它是iOS很早版本就有的类,不必去在代码中判断如果iOS版本小于8,而去用AlertView或者ActionSheet。

当app运行的iOS版本中没有UIAlertController的时候,GJAlertController这个类库会自动用UIAlertView、UIActionSheet去帮你实现你想要的功能。

###使用: #####1.直接把GJAlertController文件夹下的GJAlertAction.h/.m、GJAlertController.h/.m、UIViewController+Alert.h/.m文件放入工程中即可,无需引入其他库。

#####2.Podfile文件中添加:pod 'GJAlertController' #####然后重新update

###用法:就是直接用UIAlertController,不用考虑版本兼容的问题。

//创建instance
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];

//添加action
[alertVC addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"%@", action.title);
}]];
    
//添加action
[alertVC addAction:[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"%@", action.title);
}]];

//添加textField, 由于UIAlertView最多只支持添加两个textField,所以这里如果你添加了多个textField,iOS8之前最多显示两个,iOS8及其之后会显示出多个。
[alertVC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"huhu";
}];

//展示
[self presentViewController:alertVC animated:YES completion:nil];

如果要使用actionSheet把创建时候的type改成UIAlertControllerStyleActionSheet。

如果想测试GJAlertController的作用,又没有iOS7的设备的话,可以直接使用GJAlertController、GJAlertAction及其相关的枚举值,用法就是把上面用法中的UI前缀换成GJ就可以了,但是显示的时候不能调用

[self presentViewController:alert animated:YES completion:nil];

如果要显示Alert调用:

[alert testShow];

如果要显示ActionSheet调用:

[actionSheet testShowActionSheet];

gjalertcontroller's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.