iOS开发中 常用枚举和常用的一些运算符(易错总结)
#define kColorValue arc4random_uniform(256)/255.0 // arc4random_uniform(256)/255.0; 求出0.0~1.0之间的数字 view.backgroundColor = [UIColor colorWithRed:kColorValue green: kColorValue blue: kColorValue alpha: 0.5];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(fromOutToInside) userInfo:nil repeats:YES];
- (BOOL)textFieldShouldReturn:(UITextField *)textField;{ [textField resignFirstResponder]; return YES; }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ for (int i = 0; i < 5; i ++ ) { [field resignFirstResponder]; }
label.layer.cornerRadius
=
10;//切圆角
(圆角)
=
UITextBorderStyleRoundedRect;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(printHelloword) userInfo:nil repeats:YES];
_field.clearButtonMode = UITextFieldViewModeAlways;
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: [UIColor whiteColor], UITextAttributeFont : [UIFont boldSystemFontOfSize:18]};
- (NSString *)ittemDisposeIdcardNumber:(NSString *)idcardNumber { //星号字符串 NSString *xinghaoStr = @""; //动态计算星号的个数 for (int i = 0; i < idcardNumber.length - 7; i++) { xinghaoStr = [xinghaoStr stringByAppendingString:@"*"]; } //身份证号取前3后四中间以星号拼接 idcardNumber = [NSString stringWithFormat:@"%@%@%@",[idcardNumber substringToIndex:3],xinghaoStr,[idcardNumber substringFromIndex:idcardNumber.length-4]]; //返回处理好的身份证号 return idcardNumber; }
CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number;); [attributedString addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0, [attributedString length])]; //调整行间距 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_messageLabel.text length])]; _messageLabel.attributedText = attributedString;
location = [[CLLocationManager alloc] init]; location.delegate= self; [locationrequestAlwaysAuthorization];
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { switch (status) { casekCLAuthorizationStatusNotDetermined: if ([location respondsToSelector:@selector(requestAlwaysAuthorization)]) { [locationrequestAlwaysAuthorization]; } break; default: break; } }
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor { NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text]; //设置字号 [str addAttribute:NSFontAttributeName value:font range:range]; //设置文字颜色 [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range]; labell.attributedText = str; }
-(NSString *)sexStrFromIdentityCard:(NSString *)numberStr{ NSString *result = nil; BOOL isAllNumber = YES; if([numberStr length]<17) return result; //**截取第17为性别识别符 NSString *fontNumer = [numberStr substringWithRange:NSMakeRange(16, 1)]; //**检测是否是数字; const char *str = [fontNumer UTF8String]; const char *p = str; while (*p!='\0') { if(!(*p>='0'&&*p<='9')) isAllNumber = NO; p++; } if(!isAllNumber) return result; int sexNumber = [fontNumer integerValue]; if(sexNumber%2==1) result = @"男"; ///result = @"M"; else if (sexNumber%2==0) result = @"女"; //result = @"F"; return result; }
+ (NSArray*)getAllSystemFonts; { NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; NSArray* familys = [UIFont familyNames]; for (id obj in familys) { NSArray* fonts = [UIFont fontNamesForFamilyName:obj]; for (id font in fonts) { [array addObject:font]; } } return array; } + (UIFont*)getCurrentFont { //判断系统字体的size,返回使用的字体。 UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; return font; }
CGSize size1 = [内容 sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:CGSizeMake(宽度, 10000)]; -(CGFloat)getHeight:(NSString *)text andWidth:(CGFloat)width andFont:(UIFont *)font { CGRect frame = [text boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil] ; return frame.size.height ; }
将Base64编码的文本转换成普通文本
/// <summary> /// 将Base64编码的文本转换成普通文本 /// </summary> /// <param name="base64">Base64编码的文本</param> /// <returns></returns> public static string Base64StringToString(string base64) { if (base64 != "") { char[] charBuffer = base64.ToCharArray(); byte[] bytes = Convert.FromBase64CharArray(charBuffer, 0, charBuffer.Length); string returnstr = Encoding.Default.GetString(bytes); return returnstr; } else { return ""; } } #endregion #region 字符串转为base64字符串 public static string changebase64(string str) { if (str != "" && str != null) { byte[] b = Encoding.Default.GetBytes(str); string returnstr = Convert.ToBase64String(b); return returnstr; } else { return ""; } } #endregion
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Contacts.plist" ofType:nil];
NSDictionary *dic = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; self.navigationController.navigationBar.titleTextAttributes = dic;
[self addTapGesture];
- (void)addTapGesture{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap : )]; [self.aview.aImageView addGestureRecognizer:tap]; [tap release]; }
//实现轻拍手势的方法
- (void)handleTap : (UITapGestureRecognizer *)tap{ //添加ActionSheet控件 提示选项框 UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照" otherButtonTitles:@"从手机中选择", nil]; //在当前界面显示actionSheet对象 [actionSheet showInView:self.view]; [actionSheet release]; }
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 0: //拍照 NSLog(@"拍照"); [self pickerPictureFromCamera]; break; case 1: //从相册中读取照片 NSLog(@"从相册中读取照片"); [self pickerPictureFormPhotoAlbum]; break; default: break; } }
//拍照
- (void)pickerPictureFromCamera{ //判断前摄像头是否可以使用 BOOL isCameera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]; // UIImagePickerControllerCameraDeviceFront 前摄像头 // UIImagePickerControllerCameraDeviceRear //后摄像头 if (!isCameera) { NSLog(@"没有摄像头可以使用"); return; } //初始化图片选择控制器对象 UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init]; //设置图片选择器选取图片的样式 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //设置取出来的图片是否允许编辑 imagePicker.allowsEditing = YES; //设置代理 imagePicker.delegate = self; //把手机相机推出来 [self presentViewController:imagePicker animated:YES completion:nil]; [imagePicker release]; }
//从相册中取出相片
- (void)pickerPictureFormPhotoAlbum{ UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init]; //设置图片格式 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //设置允许编辑 imagePicker.allowsEditing = YES; //设置代理 imagePicker.delegate = self; [self presentViewController:imagePicker animated:YES completion:nil]; [imagePicker release]; }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ //从字典中取出编辑的key值,对应的照片 self.aview.aImageView.image = [info objectForKey:UIImagePickerControllerEditedImage]; //自己推出来的自己收回去 [self dismissViewControllerAnimated:YES completion:nil]; }
- (void)parserData : (NSData *)data{ //解析: NSMutableDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; // NSLog(@"%@",dataDic); 验证! //取出results key值对应的数组 NSArray *array = dataDic[@"results"]; //遍历数组的字典,并使用给Business对象赋值 for (NSDictionary *dic in array) { //创建数据模型对象 Business *bus = [[Business alloc]init]; //使用kvc给bus赋值 [bus setValuesForKeysWithDictionary:dic]; //添加到存储所有商户信息的数组 [self.dataSource addObject:bus]; //释放 [bus release]; // NSLog(@"%@",self.dataSource); 验证! } //刷新ui界面 [self.tableView reloadData]; }
'-[Person encodeWithCoder:]: unrecognized selector sent to instance 0x7fc831d9c880’
方法没实现
+ (CGSize)getStringSize:(NSString *)text strMaxWidth:(CGFloat )width fontSize:(UIFont *)fontSize{ CGSize constraint = CGSizeMake(width, MAXFLOAT); NSDictionary *dict = [NSDictionary dictionaryWithObject:fontSize forKey: NSFontAttributeName]; CGSize size = CGSizeZero; if (isAboveIOS7) { size = [text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dict context:nil].size; return size; } size = [text sizeWithFont:fontSize constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping]; return size; }
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { //获取segue起始端的视图控制器对象 RootViewController *rootVC = [segue sourceViewController]; //通过segue完成跳转的时候会触发这个方法,在跳转之前触发,一般用来传值 //获取push过去后的视图控制器对象 DetailViewController *detailVC = [segue destinationViewController]; //把textField中的内容取出来赋值给下一个界面的属性 detailVC.string = rootVC.textField.text;// rootVC.textField.text 相当于 self.textField.text }
self.ageLabel.text = [NSString stringWithFormat:@"%ld",person.age];
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
从这个函数的说明我们可以知道,如果你subclass一个UIViewController,不管有没有使用NIB, [super initWithNibName:bundle]这个方法必须被调用, 这个方法会在如下两种情况下被调用:
- 显示调用, 指定一个nib名称,系统会去找指定的nib
- 在父类的Init方法中被调用,如果这种情况,两个参数都会是nil,系统会去找和你自定以的UIViewController相同名字的nib
NSBundle Nib装载方法
guide 文档详细介绍了nib的装载过程,例如可以用loadNibNamed:owner方法,但是这个方法只是做了loadNib的事情。
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://linode-back-cn.b0.upaiyun.com/articles/d34/372/db6edd24d68302930fbc5fd44c.html"]]]; [self.webView loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:nil];
1、在appDelegate中加入一个navigation用来控制所有的页面跳转
UILabel *descLable=[[UILabel alloc] init]; [descLable setNumberOfLines:0]; descLable.lineBreakMode = UILineBreakModeCharacterWrap; descLable.text = _newsListModel.news_comtent; descLable.font = [UIFont systemFontOfSize:12]; UIFont *font = [UIFont fontWithName:@"Arial" size:12]; CGSize size = CGSizeMake(300, MAXFLOAT); CGSize labelsize = [_newsListModel.news_comtent sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap]; [descLable setFrame:CGRectMake(10, 280,300, labelsize.height)]; [headView addSubview:descLable]; view.backgourd.color = [uicolor colorwithred green blue alpha:0.5]
2.添加如下方法:
plaincopy
- - (float)checkTmpSize
- {
- float totalSize = 0;
- NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
- for (NSString *fileName in fileEnumerator)
- {
- NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName];
- NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
- unsigned long long length = [attrs fileSize];
- totalSize += length / 1024.0 / 1024.0;
- }
- // NSLog(@"tmp size is %.2f",totalSize);
- return totalSize;
- }
新版的SDImageCache类,已增加此方法
plaincopy
- [[SDImageCache sharedImageCache] getSize];
plaincopy
- #pragma 清理缓存图片
- - (void)clearTmpPics
- {
- [[SDImageCache sharedImageCache] clearDisk];
- // [[SDImageCache sharedImageCache] clearMemory];//可有可无
- DLog(@"clear disk");
- float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize];
- NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024];
- [configDataArray replaceObjectAtIndex:2 withObject:clearCacheName];
- [configTableView reloadData];
- }
iOS开发中 常用枚举和常用的一些运算符(易错总结)的更多相关文章
- iOS开发中常用的数学函数
iOS开发中常用的数学函数 /*---- 常用数学公式 ----*/ //指数运算 3^2 3^3 NSLog(,)); //result 9 NSLog(,)); //result 27 //开平方 ...
- IOS开发-OC学习-常用功能代码片段整理
IOS开发-OC学习-常用功能代码片段整理 IOS开发中会频繁用到一些代码段,用来实现一些固定的功能.比如在文本框中输入完后要让键盘收回,这个需要用一个简单的让文本框失去第一响应者的身份来完成.或者是 ...
- iOS开发中 workspace 与 static lib 工程的联合使用
在iOS开发中,其实workspace的使用没有完全发挥出来,最近做了一些研究,也想把之前写过的代码整理下,因为iOS里面的布局方式,交互方式也就那么几种.所以,整理好了之后,更能快捷开发,而且能够形 ...
- iOS开发中调试小技巧
对于软件开发而言,调试是必须学会的技能,重要性不言而喻.对于调试的技能,基本上是可以迁移的,也就是说你以前在其他平台上掌握的很多调试技巧,很多也是可以用在iOS开发中.不同语言.不同IDE.不同平台的 ...
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- 多线程在iOS开发中的应用
多线程基本概念 01 进程 进程是指在系统中正在运行的一个应用程序.每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内. 02 线程 2-1 基本概念 1个进程要想执行任务,必须得有线程 ...
- ios开发中超简单抽屉效果(MMDrawerController)的实现
ios开发中,展示类应用通常要用到抽屉效果,由于项目需要,本人找到一个demo,缩减掉一些不常用的功能,整理出一个较短的实例. 首先需要给工程添加第三方类库 MMDrawerController: 这 ...
- IOS开发中单例模式使用详解
第一.基本概念 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问. 第二.在IOS中使用单例模式的情 ...
- iOS 开发中常见的设计模式
最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...
- iOS开发中的MVC设计模式
我们今天谈谈cocoa程序设计中的 模型-视图-控制器(MVC)范型.我们将从两大方面来讨论MVC: 什么是MVC? M.V.C之间的交流方式是什么样子的? 理解了MVC的概念,对cocoa程序开发是 ...
随机推荐
- java常用的几种线程池比较
1. 为什么使用线程池 诸如 Web 服务器.数据库服务器.文件服务器或邮件服务器之类的许多服务器应用程序都面向处理来自某些远程来源的大量短小的任务.请求以某种方式到达服务器,这种方式可能是通过网络协 ...
- JS运行机制之 Event Loop 的思考
先举个栗子,如下: for (var i = 0; i < 5; i++) { setTimeout(function() { console.log('i: ',i); //一秒之后输出几乎没 ...
- 各种电子面单Api接口免费对接-快宝开放平台
1.什么是电子面单? 快递公司联合向商家提供的一种通过热敏纸打印输出纸质物流面单的物流服务,并且承载分单自动化算法等数据服务,是快递行业赋能的基础产品和服务. 2.电子面单长什么样? 各快递公司有自己 ...
- CentOS6.8虚拟机安装及ORALCE安装记录
CENTOS6.8安装数据库及设置自启动脚本教程 作者:张欣橙 本文所需要的所有参数均位于文末附录中 一.新建虚拟机 选择下一步 选择下一步 选择稍后安装操作系统 选择LINUX 版本 CentOS ...
- Bootstrap 遮罩层实现方式
直接上代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...
- 解析配置文件redis.conf
units单位: # 1k => 1000 bytes # 1kb => 1024 bytes # 1m => 1000000 bytes # 1mb => 1024*1024 ...
- python序列化pickle/cPickle
一.pickle/Cpickle简介 Python序列化的概念很简单.内存里面有一个数据结构,你希望将它保存下来,重用,或者发送给其他人.你会怎么做?这取决于你想要怎么保存,怎么重用,发送给谁.很多游 ...
- 跟着大佬重新入门DP
数列两段的最大字段和 POJ2479 Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41231 Acce ...
- 小知识点 取消button动作 和取巧按钮高亮
如果让按钮在点击时不变暗 进行下面设置: 如果使butten失去动画效果进行下面设置:(一般用于图片+文字,效果等于可以加图片班的label,当然label不能加图片)
- django之允许外部机器访问
开开启django时,使用0.0.0.0:xxxx,作为ip和端口例如: python3 manage.py runserver 0.0.0.0:9000 然后在settings里修改ALLOWED_ ...