STAlertView

The idea of this component is to improve the readability while using the native UIAlertView. The UIKit alert view works with delegates. When you have two or more alerts at the same controller, it becomes a problem because you have to use the TAG to identify from which UIAlertView comes the user.

设计这个控件的目的是为了增强系统原生UIAlertView的可用性,UIKit的alert view是用代理的方式工作的。当你在一个控制器中有着两个或更多个alert时,问题来了(学挖掘机哪家强-_-|||),你需要用TAG值来标示不同的UIAlertView。

With STAlertView you will be able to define the behavior of the 'Ok' and 'Cancel' button, at the same place where you declare the alert view. So, let's see some code:

使用STAlertView的话,在block中标示就行了。

[[STAlertView alloc] initWithTitle:@"Title"
message:@"Message"
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok"
cancelButtonBlock:^{
NSLog(@"do something at cancel"); } otherButtonBlock:^{
NSLog(@"do something at ok"); }];

And that's it, no pieces of code everywhere, just a few lines and all the related code together. As it is a native UIAlertView, the result of using STAlertView is like the native one:

就这些,你不用在其他地方写代码了,仅仅几行代码就行了。

This component has been made thanks to the answer of Ricky Helgesson at StackOverflow.

设计这个组件归功于StackOverflow上的Ricky Helgesson所提供的答案。

Demo usage

To run the example project, clone the repo, and run pod install from the Example directory first.

为了运行demo,复制repo,运行pod,安装即可

Requirements

Is compatible with ARC and non-ARC.

兼容ARC和non-ARC

Installation

STAlertView is available through CocoaPods. To install it, simply add the following line to your Podfile:

STAlertView支持CocoaPods,使用下面的Podfile即可:

pod "STAlertView"

Then at the view controller that you want to show the alert view add at the .h:

在你需要显示的控制器里面,添加头文件即可:

#import <STAlertView/STAlertView.h>
...
@property (nonatomic, strong) STAlertView *alertView;
...
@end

And at the .m:

...
self.alertView = [[STAlertView alloc] initWithTitle:@"Title of the alert"
message:@"Message you want to show"
cancelButtonTitle:@"No" otherButtonTitles:@"Yes"
cancelButtonBlock:^{
// Code todo when the user cancel
...
} otherButtonBlock:^{
// Code todo when the user accept
...
}];
...

[翻译] STAlertView的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. Chapter 3 Phenomenon——17

    Dr. Cullen raised his eyebrows. "Do you want to stay?" Cullen医生抬起了他的眉毛“你想待在这吗?” "No, ...

  2. python笔记09-----装饰器,生成器,迭代器

    1.装饰器 定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器的知识储备: 1.      函数即“变 ...

  3. docker仓库--使用tenxcloud

    上传镜像 1. 在本地 docker 环境中输入以下命令进行登录 sudo docker login index.tenxcloud.com 2. 然后,对本地需要 push 的 image 进行标记 ...

  4. maven 中 jar管理

    慢慢补充 将本地jar添加到maven的仓库中 mvn install:install-file -DgroupId=org.geotools -DartifactId=gt-swing -Dvers ...

  5. Carrierwave 如何配置合理的上传文件名(转自李华顺)

    一直在寻找一个好的 Carrierwave 上传文件命名结构(GridFS),今天终于找到了,这个方式比较靠谱. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...

  6. js 3行代码,最简易实现div效果悬浮

    简易实现浮动效果的首要因素是:获取滚动条距离浏览器顶部的距离,下面直接贴代码: <!DOCTYPE html> <html> <head> <meta cha ...

  7. 虚拟机安装Linux中常见异常及解决办法

    如果接着下去的提示按Test 的话 会出现Unable to read the disc checksum from the primary volume descriptor. This proba ...

  8. css3如何实现圆角边框

    圆角边框是css3新增属性,在圆角边框出现之前,前端开发有的采用整块的圆角图片作为背景,有的采用小的圆角图片分别放在元素的四角,非常麻烦,灵活性差,也达到降低了网站的整体性能,而圆角边的出现则降低了开 ...

  9. [日常] nginx与HTTP cache

    去年的事,随便记记 =============================================================2017年12月11日 记录: nginx缓存:ngx_h ...

  10. java并发编程的艺术(一)---锁的基本属性

    本文来源于翁舒航的博客,点击即可跳转原文观看!!!(被转载或者拷贝走的内容可能缺失图片.视频等原文的内容) 若网站将链接屏蔽,可直接拷贝原文链接到地址栏跳转观看,原文链接:https://www.cn ...