本文中,第一节将介绍关联对象及如何关联对象,第二节将介绍关联对象最常用的一个实战场景:为分类添加属性,第三节将介绍关联对象另一个很重要的实战场景:为UI控件(比如,UIAlertView以及UIButton...因为在分类中 @property 并不会自动生成实例变量以及存取方法,所以一般使用关联对象为已经存在的类添加 “属性”。...2.3 实战场景 需求:比如你为UIView添加事件,可以在上面添加一个UITapGestureRecognizer,但是这个点击事件无法携带NSString信息(虽然可以携带int类型的tag),这就无法让后续响应该事件的方法区分到底是哪里激活的事件...那么,你是否能为这种添加事件的方式携带另外的信息呢?...) //类拓展添加属性 @property (nonatomic, strong) NSString *dataStr; @end UITapGestureRecognizer+NSString.m
这两天项目中统一对已经被iOS API废弃的UIAlertView和UIActionSheet进行替换,我们知道,UIAlertView和UIActionSheet都已经被iOS的API所废弃了。...+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle...,并味蕾个按钮添加点击事件;二是根据需要添加文本框,用于和用户进行更多的交互。...1.2.1 UIAlertController上添加按钮 UIAlertController上的每一个按钮都是一个UIAlertAction,与UIAlertController的类型是UIAlertView...textField就会调用 这个block"); }]; 但是,值得注意的有两点: 文本框的添加只能是在UIAlertController的风格类型为UIAlertView时才有 文本框的添加多个
iOS8统一的系统提示控件——UIAlertController 一、引言 相信在iOS开发中,大家对UIAlertView和UIActionSheet一定不陌生,这两个控件在UI设计中发挥了很大的作用...在iOS8之后,系统吸引了UIAlertController这个类,整理了UIAlertView和UIActionSheet这两个控件,在iOS中,如果你扔使用UIAlertView和UIActionSheet...这里有旧的代码的使用方法: UIAlertView使用:http://my.oschina.net/u/2340880/blog/408873。...,UIAlertAction类的构造十分简单,如下: //初始化方法 + (instancetype)actionWithTitle:(nullable NSString *)title style:(...*title; 设置警示控件的标题 @property (nullable, nonatomic, copy) NSString *message; 设置警示控件的信息 @property (nonatomic
*)error; - (void) restoreTransaction: (SKPaymentTransaction *)transaction; -(void)provideContent:(NSString...*)product; -(void)recordTransaction:(NSString *)product; @end .m文件 #import "RechargeVC.h" //在内购项目中创的商品单号...NSLog(@"-----已经购买过该商品 --------"); case SKPaymentTransactionStatePurchasing: //商品添加进列表...NSLog(@"-----商品添加进列表 --------"); break; default: break...NSString *product = transaction.payment.productIdentifier; if ([product length] > 0) { NSArray
工欲善其事必先利器,在检查设备的网络状态前,我们要先实现两个步骤: 下载,添加Reachability类。...为项目添加SystemConfiguration.framework框架。 ...添加方法: 1) 选中项目名称 2)选中TARGETS 3)选中Build Phases 4)在Link Binary With Libraries中添加。 ?...将Reachability.h和 Reachability.m文件添加到项目中。 ...*) msg 60 { 61 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络状态" message:msg delegate
Realm/Realm.h> #import @interface Student : RLMObject @property int age; @property NSString...*alert = [[UIAlertView alloc] initWithTitle:@"Sucess"...otherButtonTitles:nil]; [alert show]; return ; } NSString...*filter = [NSString stringWithFormat:@"age > %d", [_filterTF.text intValue ]]; if (_realm) {...- (void)setDefaultRealmForUser:(NSString *)username { RLMRealmConfiguration *config = [RLMRealmConfiguration
步骤一:添加textfield协议‘ @interface LsGeXingQianMingVC () 步骤2:设置代理 _GeXingQianMingTiefield.delegate...)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString...相反 if ([string isEqualToString:@"\n"]) //按会车可以改变 { return YES; } NSString...40) { //如果输入框内容大于20则弹出警告 textField.text = [toBeString substringToIndex:20]; UIAlertView...*alert = [[UIAlertView alloc] initWithTitle:nil message:@"超过最大字数不能输入了" delegate:nil cancelButtonTitle
IOS中UIAlertView(警告框)常用方法总结 一、初始化方法 - (instancetype)initWithTitle:(NSString *)title message:(NSString...*)message delegate:(id /**/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle...otherButtonTitles:(NSString *)otherButtonTitles, ...; 这个方法通过设置一个标题,内容,代理和一些按钮的标题创建警告框,代码示例如下: UIAlertView...二、属性与方法解析 标题属性 @property(nonatomic,copy) NSString *title; 内容属性 @property(nonatomic,copy) NSString *message...; 添加一个按钮,返回的是此按钮的索引值 - (NSInteger)addButtonWithTitle:(NSString *)title; 返回根据按钮索引按钮标题 - (NSString
UISegmentedControl 控件属性 (1) Style 属性 Style 属性 : -- Plain : 分段控件使用最普通的风格; -- Bordered : 在最普通风格上添加一圈边框...简单的对话框示例 (1) 创建 UIAlertView API 创建方法 : [[UIAlertView alloc] initWithTitle:NSString *)#> message...:NSString *)#> delegate: cancelButtonTitle:NSString *)#> otherButtonTitles:NSString...clickedButtonAtIndex:(NSInteger)buttonIndex{ NSString * msg = [NSString stringWithFormat:@"点击了按钮...* alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat : @"点击了第 %
项目中需要添加MessageUi.framework。头文件加入MFMailComposeViewControllerDelegate。...)title msg: (NSString )msg { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title...init]; mailPicker.mailComposeDelegate = self; //设置主题 [mailPicker setSubject: @"eMail主题"]; // 添加发送者...; //[picker setCcRecipients:ccRecipients]; //[picker setBccRecipients:bccRecipients]; // 添加图片...; NSString body = @"&body=email body!"
场景: 在一个VC中,为一个UICollectionViewCell中的图片添加长按图片保存的事件。...长按保存图片 前提:infoPlist中添加相应权限:Privacy - Photo Library Additions Usage Description。否则进行保存图片的时候APP会奔溃。...property (weak, nonatomic) IBOutlet UILabel *pageLabel; @property (nonatomic, strong) NSMutableArrayNSString...UIActionSheet实现底部弹框 给CollectionViewCell中的UIImageView添加事件 #pragma - mark - UICollectionViewDataSource..., UIAlertViewDelegate > 修改点2:VC添加两个属性 @property (nonatomic , strong) UIAlertView *myAlertView; @property
CGContextAddLineToPoint(context, pX, pY); //画线 CGContextStrokePath(context); } } @end 界面添加验证码...systemFontOfSize:12]; label.textColor = [UIColor grayColor]; [self.view addSubview:label]; //添加输入框...判断输入的是否为验证图片中显示的验证码 if ([_input.text isEqualToString:authCodeView.authCodeStr]) { //正确弹出警告款提示正确 UIAlertView... *alview = [[UIAlertView alloc] initWithTitle:@"恭喜您 ^o^" message:@"验证成功" delegate:self cancelButtonTitle...input.layer addAnimation:anim forKey:nil]; } return YES; } #pragma mark 警告框中方法 -(void)alertView:(UIAlertView
*alertView = [[UIAlertView alloc] initWithTitle:@"方式一" message:@"这是OC原生的弹出窗" delegate:self cancelButtonTitle...关于这种方式调用OC方法,唐巧早期有篇文章有过介绍: 关于UIWebView和PhoneGap的总结 方式二 在iOS 7之后,apple添加了一个新的库JavaScriptCore,用来做JS交互,...documentView.webView.mainFrame.javaScriptContext"]; 再然后定义好JS需要调用的方法,例如JS要调用share方法: 则可以在UIWebView加载url完成后,在其代理方法中添加要调用的...*alertView = [[UIAlertView alloc] initWithTitle:@"方式二" message:@"这是OC原生的弹出窗" delegate:self cancelButtonTitle...OC调用JS篇 方式一 NSString *jsStr = [NSString stringWithFormat:@"showAlert('%@')",@"这里是JS中alert弹出的message"]
继承自 UIView WKWebView的特点: 性能高,稳定性好,占用的内存比较小, 支持JS交互 支持HTML5 新特性 可以添加进度条(然并卵,不好用,还是习惯第三方的)。...:sendJsStr]; } 11.为webView添加背景图片: approvalWebView.backgroundColor=[UIColor clearColor]; approvalWebView.opaque...=NO;//这句话很重要,webView是否是不透明的,no为透明 在webView下添加个imageView展示图片就可以了 12.获取webView页面内容信息: NSString *docStr=...*)message initiatedByFrame:(id)frame { UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle...*)message initiatedByFrame:(id)frame { UIAlertView *confirmDiag = [[UIAlertView alloc] initWithTitle
64 typedef unsigned long NSUInteger; #else typedef unsigned int NSUInteger; #endif 例子: 下面这个例子,将输出IPA NSString...NSRange range = {25, 3}; NSLog (@"Beer shortname: %@", [homebrew substringWithRange:range]); 搜索字符串: NSString...NSStringFromRange()方法,将一个NSRange返回一个NSString。...而另外一个函数NSRangeFromString()则是将NSString转换为NSRange 下面这个例子将从后向前反向搜索字符串: NSString *homebrew = @"Imperial India
mailPicker setToRecipients:[NSArray arrayWithObjects:@”aaaaa@163.com”, @”aaaaaa@qq.com”, nil]]; //可以添加抄送...[mailPicker setCcRecipients:[NSArray arrayWithObject:@”aaaaa@qq.com”]]; //可以添加暗抄送...case MFMailComposeResultFailed: mes = @”试图保存或者发送邮件失败“; break; default: break; } UIAlertView...*alter = [[UIAlertView alloc] initWithTitle:@”提醒“ message:mes delegate:self cancelButtonTitle:nil otherButtonTitles...; case MessageComposeResultFailed: mes = @”发送短信失败“; break; default: break; } UIAlertView
(一)UIAlertView 1.默认样式 // UIAlertView iOS8开始 被废弃 - (void)defaultAlert { // iOS8被废弃 UIAlertView...*alert = [[UIAlertView alloc] initWithTitle:nil message:@"测试" delegate:self cancelButtonTitle:@"取消"...plainTextAlert.gif 3.带有密文输入框 - (void)secureText { // iOS8被废弃 UIAlertView *alert = [[UIAlertView...旨在替代UIAlertView和UIActionSheet这两个控件。...我们知道,使用UIAlertView和UIActionSheet需要遵守对应的协议并实现相应的方法,因为UIAlertView和UIActionSheet采用delegate的方式处理事件。
* message = [NSString stringWithFormat:@"倒计时 剩余 %d", second]; //创建警告框 UIAlertView * alert =...* alert = [[UIAlertView alloc] initWithTitle:@"UIPickerView 提示" message:[NSString stringWithFormat :...* alert = [[UIAlertView alloc] initWithTitle:@"UIPickerView 提示" message:[NSString stringWithFormat :...style:UIBarButtonItemStyleBordered target:self action:@selector(clickCodeItem:)]; //创建 一个 系统的添加...UIBarButtonItem * bi5 = [[UIBarButtonItem alloc] initWithCustomView:progress]; //将上面创建的按钮添加到工具条中
这里,我就展示一个自己定义的UIAlertView效果控件,视图出现的时候动画-先放大-再缩小-最后成正常比例,消失的时候缩小加渐隐.调用也非常方便,不须要像系统先创建后,我在类内部就已经写好了,仅仅须要...*)title cancelButtonTitle:(NSString *)cancelTitle firstButtonTitles:(NSString *)firstTitle senondButtonTitles...:(NSString *)secondTitle thirdButtonTitles:(NSString *)thirdTitle; // 利用block将button的点击事件传出去 @property...*)title cancelButtonTitle:(NSString *)cancelTitle firstButtonTitles:(NSString *)firstTitle senondButtonTitles...:(NSString *)secondTitle thirdButtonTitles:(NSString *)thirdTitle{ self = [super initWithFrame:CGRectMake
默认的,UIAlertView都有一个或者多个按钮,如果你想创建没有按钮的UIAlertView,可以使用以下的方法: UIAlertView *alert; ......上面的标题可能有些靠上,可以用过给标题增加回车的方式,使标题居中: UIAlertView *alert; ......如果你还想给UIAlertView添加一个等待提示符,则可以这么做: UIAlertView *alert; ......解除UIAlertView的显示 因为这个AlertView没有按钮,所以就不能通过点击按钮将这个提示框去掉。可以通过程序的方式,将这个窗口关掉。...dismissWithClickedButtonIndex:0 animated:YES]; ---- Previous Three20中给TTPhotoViewController添加播放按钮
领取专属 10元无门槛券
手把手带您无忧上云