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程序开发是 ...
随机推荐
- 基本数据类型 异常 数组排序 JVM区域划分
Day01 1.基本数据类型各占几个字节 Byte 1 short2 int4 long8 float4 double6 char2 boolean1 Byte b1=3,b2= ...
- 利用Python进行数据分析——重要的Python库介绍
利用Python进行数据分析--重要的Python库介绍 一.NumPy 用于数组执行元素级计算及直接对数组执行数学运算 线性代数运算.傅里叶运算.随机数的生成 用于C/C++等代码的集成 二.pan ...
- Java第4次实验提纲(面向对象2-继承、多态、抽象类与接口与Swing)
PTA 题集面向对象2-进阶-多态接口内部类 第1次实验 1.1 题集5-1(Comparable) 难点:如果传入对象为null,或者传入对象的某个属性为null,怎么处理? 1.2 题集5-2(C ...
- 安卓高级9 shareSDK 第三方登陆和分享Mob
ShareSDK推荐此官网地址 官网注册和申请key流程 注册 略 进入后台创建应用得到可以 下载SDK 解压下载的压缩包 第三方平台申请key 如果你想申请QQ登陆或者分享需要去腾讯开发者申请,申请 ...
- 负载均衡LVS(DR模式)安装实战
1.编译安装ipvsadm 首先从LVS官网下载tarball,解压后make && make install即可. 要注意的是LVS的依赖有:popt-static.libnl.ke ...
- 一道有趣的Twitter技术面试题
来自:http://blog.jobbole.com/50705/ 看下面这个图片” “在这个图片里我们有不同高度的墙.这个图片由一个整数数组所代表,数组中每个数是墙的高度.上边的图可以表示为数组[2 ...
- Maven坐标机制
Maven为所有的项目引入了坐标,基于坐标机制可以唯一定位一个项目. 坐标详解 以spring-core-2.5.6.jar的坐标定义为例,说明组成坐标的所有元素:groupId.artifactId ...
- Gazebo機器人仿真學習探索筆記(一)安裝與使用
Gazebo提供了多平臺的安裝和使用支持,大部分主流的linux,Mac以及Windows,這裏結合ROS以Ubuntu爲例進行介紹. 首先是參考資料:http://gazebosim.org/tut ...
- FFmpeg的HEVC解码器源代码简单分析:概述
===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...
- 有奖试读—Windows PowerShell实战指南(第2版)
为什么要学PowerShell? Windows用户都已习惯于使用图形化界面去完成工作,因为GUI总能轻易地实现很多功能,并且不需要记住很多命令.使得短时间学会一种工具成为可能. 但是不幸的是,GUI ...