[翻译] STAlertView

简介:

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 ... }]; ...

 

目录
相关文章
|
存储 自然语言处理 前端开发
从零写一个Recoil(翻译)
Rewriting Recoil from scratchrecoil是facebook编写的一个库,它之所以诞生是因为人体工程学、context的性能问题和useState。这是一个非常聪明的库,几乎每个人都会找到它的用途——如果你想了解更多,请查看这段解释视频。刚开始我被图论和recoil惊到了,但渐渐的理解后,感觉也没那么特别了。也许我也可以实现一个类似的东西。我自己实现的版本和recoil
195 0
从零写一个Recoil(翻译)
《Wir wilden weisen Frauen》翻译——<连载>
上周去逛图书馆,借了本德语原版的书。今天突然想起来了,就翻开来看。我不知道这本书是否有中文版的,不管有没有吧,我尝试翻译一下以提高自身的德语水平。每天花上一个半小时来翻译,我想应该不能翻译出来几句的。
765 0
|
开发工具 iOS开发 MacOS
|
存储 iOS开发 Perl
|
Java iOS开发 Spring
|
API Apache iOS开发
|
iOS开发