写一些自己的总结和自己平常的积累,对的错的勿见怪!!!我只是为了自己以后查找方便 ~_~! 我会持续的更新的.

一,设置导航栏返回按钮的图片和设置导航条上返回按钮旁边的文字(这里写的是让文字不在屏幕上显示)

  

UIImage  * image = [UIImage imageNamed:@"返回按钮图片"];

//设置导航条返回按钮的图片

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

//设置导航条返回按钮旁边的文字不显示

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

 

二,当我们在界面上添加导航条之后继续添加其他控件,会发现有的时候界面的大小不是我们设想的那样显示,比如 textView.原因是因为使用导航条跳转的时候,textView它会减去64像素,也就是导航条加状态栏的高度,都是导航条引起的,使用下面那句话进行解决:

 

self.automaticallyAdjustsScrollViewInsets = NO;

 

三,设置请求内容类型(基于AFNetWorking库)

 

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html; charset=utf-8",@"application/json", @"text/json", @"text/javascript",@"text/plain; charset=utf-8",nil];

//设置请求的数据类型

manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain //数据类型"];

 

四,有关cocoapods的设置

1,在最新的cocoapods 1.0.1 中如果按照之前的使用方法使用,会出现很多错误;

2,使用1.0.1版本的时候需要在podfile 里面的最上面输入 target '工程名' do   (此处的工程名字就是你的项目名字);

3,使用1.0.1版本的时候还需要在podfile的最下面输入 end;

4,如果是做swift第三方开发,比如ReacTiveCocoa第三方库的时候还需要在end 的下面添加 use_frameworks! ;

5,使用1.0.1版本的时候如果遇到的第三方对版本还有要求的话,需要在podfile的上面添加版本限制,比如platform:ios, ‘8.0’ ;

 

五,有关手势的设置方法  UITapGestureRecognizer

 

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];//创建手势

[self.view addGestureRecognizer:tap];//将手势添加到 mohuView上面

在这里我们有的时候会碰到疑问如果我们在父视图上创建的手势,手势效果会继续延伸到子视图上面,进而子视图会有父视图的手势效果,在这里我们要用到一个代理方法

tap.delegate = self;//设置手势代理

//移除cityHospitalV 上的手势效果( cityHospitalView是self.view上面的子视图)

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    if ([touch.view isDescendantOfView:cityHospitalV]) {

        return NO;

    }

    return YES;

}

六,更改手机上面的状态栏电池 运行商 颜色

1,首先在plist 里面添加

View controller-based status bar appearance == NO 默认是YES 设置之后代码效果才能实现

2,然后在Target -->General -->Deployment Info -->Status Bar Style里面更改为light 

或者用代码实现,具体代码自己去搜,网上很多的.

3,在当前控制器更改,这样只更改当前状态栏颜色

-(UIStatusBarStyle)preferredStatusBarStyle{

    return UIStatusBarStyleLightContent;

}

七,设置导航条及状态栏背景颜色 及导航条相关

nav.navigationBar.barTintColor = [UIColor redColor];

rightBtnTtem = [[UIBarButtonItem alloc]initWithTitle:@"当前进度0%" style:UIBarButtonItemStylePlain target:self action:nil];

    self.navigationItem.rightBarButtonItem = rightBtnTtem; //设置导航条右侧显示效果

 

 

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:17]};//设置导航条上字体颜色和大小

 

 八,获取当前项目版本号及信息

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

 

九,计算字符串的宽高和将字符串中的某一段文字设置为红色

  (1):首先应该先设置字符串的font值,之后颜值字符串的最大宽和最大高maxSize ,如果只要显示一行则宽高都设置为MAXFLOAT,如果要显示多行只需要将宽设置为限定值,将高设置为MAXFLOAT就行

CGSize maxSize = CGSizeMake(kUIScreenWidth-20,NSIntegerMax); //kUIScreenWidth 是屏幕的宽

 

CGSize labelsize = [lab.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:lab.font} context:nil].size;

labelSize就是字符串的宽高;

  (2):将字符串中的271个字之后的84为全部变成红色  (此处的String 为  NSMutableAttributedString)

[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(271, 84)];

然后设置 self.Lable.attributedText = string;

     (3): NSAttributedString 计算 NSAttributedString字符串的高度,及设置 NSAttributedString的字与字之间的间距和行与行之间的间距

//给UILabel设置行间距和字间距

-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {

    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];

    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;

    paraStyle.alignment = NSTextAlignmentLeft;

    paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距

    paraStyle.hyphenationFactor = 1.0;

    paraStyle.firstLineHeadIndent = 0.0;

    paraStyle.paragraphSpacingBefore = 0.0;

    paraStyle.headIndent = 0;

    paraStyle.tailIndent = 0;

    //设置字间距 NSKernAttributeName:@1.5f

    NSDictionary *dic = @{

                          NSFontAttributeName:font,

                          NSParagraphStyleAttributeName:paraStyle,

                          NSKernAttributeName:@1.5f,

                          };

    

    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];

    

    

    label.attributedText = attributeStr;

}

 

//计算UILabel的高度(带有行间距的情况)

-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {

    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];

    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;

    paraStyle.alignment = NSTextAlignmentLeft;

    paraStyle.lineSpacing = UILABEL_LINE_SPACE;

    paraStyle.hyphenationFactor = 1.0;

    paraStyle.firstLineHeadIndent = 0.0;

    paraStyle.paragraphSpacingBefore = 0.0;

    paraStyle.headIndent = 0;

    paraStyle.tailIndent = 0;

    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f,

                          };

    

    CGSize size = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;

    return size.height;

}

 

十,设置图片的拉伸效果(两种方法)

(1)图片的拉伸系统提供给我们的有个方法:(ios 5.0)

  - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;  

  其中leftCapWidth代表左端盖宽度,topCapHeight代表上端盖高度.系统会根据提供的两个参数自动计算 右侧和上侧端盖宽度和端盖盖度,计算方法如下:
    rightCapWidth = width - leftCapWidth - 1;
    bottomCapHeight = height - topCapHeight - 1;
最后结果就是拉伸区域是 1x1;
 image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight]; //就是我们拉伸之后的图片
(2),ios 6系统又提供一个方法
    - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode ;
  capInsets:我们可以通过设置UIEdgeInsets的top、left、bottom、right来分别指定上端盖高度、左端盖宽度、下端盖高度、右端盖宽度
  resizingMode:用来指定拉伸的模式;
 
  CGFloat top = 25; // 顶端盖高度  
  CGFloat bottom = 25 ; // 底端盖高度  
  CGFloat left = 10; // 左端盖宽度  
  CGFloat right = 10; // 右端盖宽度

  UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);  

  image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];  

//image就是我们拉伸之后的图片(如果图片的大小是 24 x 60的话 ,我们的拉伸区域是4x10);

十一,ios基础 assign copy retain weak strong 区别(简单介绍)

  (1):assign 只是简单赋值,不更改引用计数;

    copy 释放旧的对象,建立一个引用计数为1的对象,创建一个相同的对象;(新的对象和旧的对象地址不相同,但是内容相同)

    retain 释放旧的对象,将旧的对象赋值给新的对象,新的对象引用计数为1;(新的对象的地址和内容与旧的对象的地址内容相同)

  也就是说retain是指针拷贝,copy是内容拷贝,二者在拷贝之前都会释放旧的对象.

  (2):assign:在对象时基本数据类型的时候使用;

    copy:在对象是NSString的时候;

    retain:在你对象是NSObject和其他子类的时候;

  (3):在ARC状态下,weak就是assign属性,strong就是retain属性

十二,获取当前项目的版本号

    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];

十三,去除字符串中的空格和空白

    [String stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

十四,几种常用的正则

  (1)是否全为数字:   NSString *regEx =  @"^-?\\d+.?\\d?";

  (2)email:     NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

  (3)手机号码:   NSString *phoneRegex = @"^1[3|4|5|7|8][0-9]{9}$";

  (4)身份证验证:  NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$"; 注:15位身份证和18位身份证验证,此正则不能根据前面的数字判断最后一位的智能判断,后面我会单加一个身份证智能判断

例: 

- (BOOL)isPureNumandCharacters

{

    NSString *regEx =  @"^-?\\d+.?\\d?";

    NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx];

    return [pred evaluateWithObject:self];

}

  (5)身份证最后一位智能验证

身份证最后一位智能验证
+ (BOOL)checkIdentityCardNo:(NSString*)cardNo { if (cardNo.length != 18) { return NO; } NSArray* codeArray = [NSArray arrayWithObjects:@"7",@"9",@"10",@"5",@"8",@"4",@"2",@"1",@"6",@"3",@"7",@"9",@"10",@"5",@"8",@"4",@"2", nil]; NSDictionary* checkCodeDic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"0",@"X",@"9",@"8",@"7",@"6",@"5",@"4",@"3",@"2", nil] forKeys:[NSArray arrayWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil]]; NSScanner* scan = [NSScanner scannerWithString:[cardNo substringToIndex:17]]; int val; BOOL isNum = [scan scanInt:&val] && [scan isAtEnd]; if (!isNum) { return NO; } int sumValue = 0; for (int i =0; i<17; i++) { sumValue+=[[cardNo substringWithRange:NSMakeRange(i , 1) ] intValue]* [[codeArray objectAtIndex:i] intValue]; } NSString* strlast = [checkCodeDic objectForKey:[NSString stringWithFormat:@"%d",sumValue%11]]; if ([strlast isEqualToString: [[cardNo substringWithRange:NSMakeRange(17, 1)]uppercaseString]]) { return YES; } return NO; }

 十五,除去picView上面的手势

//除去再picView上面的手势  

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    if ([touch.view isDescendantOfView:picView]) {

        return NO;

    }

    return YES;

}

 十六,获取缓存路径及计算缓存文件的大小和清除缓存

//获取缓存路径

    NSString * cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    

    float fileSize = [self floderSizeAtPath:cachePath];

    

    NSString * result = [NSString stringWithFormat:@"%.2fMB",fileSize];

    NSLog(@"%@",result);

//计算缓存大小

-(float)floderSizeAtPath:(NSString *)folderPath{

    NSFileManager * manager = [NSFileManager defaultManager];

    if (![manager fileExistsAtPath:folderPath]) {

        return 0;

    }else{

        NSEnumerator * childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];

        NSString * fileName;

        long long folderSize = 0;

        while ((fileName = [childFilesEnumerator nextObject]) != nil) {

            NSString * fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];

            folderSize += [self floderSizeAtPath:fileAbsolutePath];

        }

        return folderSize/(1000.0 * 1000.0); //注意在ios系统中 1g的大小=1000m,普通的pc 1g= 1024m

    }

}

 

#pragma mark - 清除缓存

- (void)cleanCaches

{

    

    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];

    for (NSString *p in files) {

        NSError *error;

        NSString *path = [cachPath stringByAppendingPathComponent:p];

        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

            [[NSFileManager defaultManager] removeItemAtPath:path error:&error];

        }

    }

 

}

十七,ios项目在AppStore的下载地址    

  http://itunes.apple.com/cn/app/id%@     %@为itunesConnection里面的id

十八,宏定义RGBColor传十六进制及宏定义Dlog()

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]     如UIColorFromRGB(0x0000FF)

#ifdef DEBUG  //调试

#define DLog(...) NSLog(__VA_ARGS__)

#else //发布

#define DLog(...)

#endif

十九,简单的刷新界面效果

[self.view removeFromSuperview];

[[UIApplication sharedApplication].keyWindow addSubview:self.view];

二十,MJRefrsh部分

[self.tableView.mj_footer resetNoMoreData];  //重置底部显示没有更多数据了

 

 [self.tableView.mj_footer endRefreshingWithNoMoreData]  //底部显示没有更多数据了

[tabView.mj_header beginRefreshing];

tabView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

tabView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{

[tabView.mj_header endRefreshing];

[tabView.mj_footer endRefreshing];

二十一,oc和服务端交互

UIWebView 中

#import <JavaScriptCore/JavaScriptCore.h>

 

//APP端调js方法

    NSString *js = [NSString stringWithFormat:@"ywcl_rt()"];

    [self.webView stringByEvaluatingJavaScriptFromString:js];

 

 //js调app端方法appBack为APP端的方法名

   JSContext *context = [self.webView  valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

    

    @weakify(self);

    context[@"appBack"] = ^(){

NSArray * arg = [JSContext currentArguments];//js端传的参数

WKWebView 中 js调oc方法

(服务端应该填写:window.webkit.messageHandlers.aaa.postMessage({body: 'call js alert in js'});

)

 NSArray * arg = [JSContext currentArguments];

获取所传参数

 二十二,强弱指针懒加载

 

1: weak 修饰弱指针一开始的时候不能直接指向一个对象

2: strong 可以直接指向一个对象 

 二十三,获得字符串中的连续数字

 

二十四,判断版本

if([@"234" compare:@"345" options:NSCaseInsensitiveSearch] == NSOrderedDescending){ //降序

        NSLog(@"有新版本");

    }else if ([@"234" compare:@"345" options:NSCaseInsensitiveSearch] == NSOrderedAscending){//升序

        NSLog(@"mei有新版本");

    }else if ([@"234" compare:@"345" options:NSCaseInsensitiveSearch] == NSOrderedSame){

        NSLog(@"没有新版本2");

    }

 二十五,设置按钮图片和文字上下布局

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示

        [btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变

        [btn setImageEdgeInsets:UIEdgeInsetsMake(-btn.imageView.frame.size.height/2 , 0.0,0.0, -btn.titleLabel.bounds.size.width)];

 

 

 

 

 

 

 

 

 

 

posted on 2016-07-14 17:33  Smile_闪电  阅读(243)  评论(0编辑  收藏  举报

导航