iOS小方法

简介:

1.取字符串中的某段字符串 
[plain] view plaincopyprint? 
NSString *str =@"12sadfsdf56afsdf";   
NSLog(@"
%@",str); 
NSString *thrStr = [strstringByReplacingOccurrencesOfString:@"56"withString:@"88"];
NSLog(@"
%@",thrStr); 
即把12sadfsdf56afsdf中的56替换为88,替换后字符串为:12sadfsdf88afsdf


2.简单plist获取
[plain] view plaincopyprint? 
NSString *path = [[NSBundlemainBundle]pathForResource:@"Array"ofType:@"plist"];  
NSMutableDictionary *data = [[NSMutableDictionaryalloc]initWithContentsOfFile:path];  
NSLog(@"%d",[datacount]);  
NSLog(@"%@",[dataallValues]);  
NSLog(@"------------") ;   
NSArray *ary = [dataallKeys]; 
NSLog(@"%d",[arycount]); 
NSArray *array = [NSArrayarrayWithArray:ary];   
for(int i=0;i<[arraycount];i++)   
{   
    NSLog(@"\n value = %@",[arrayobjectAtIndex:i]);    
}   
NSArray *getArray = [[dataallValues]objectAtIndex:5];

NSLog(@"get_array:%@",getArray);  
 
3.状态栏和UINavigationBar设置成透明 
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];  //状态栏设置为透明 
theNavigationController.navigationBar.barStyle =UIBarStyleBlackTranslucent;   //设置navigationBar为透明

  
4.设置object圆角,如UIView、UIImageView等 
简单几步: 
一.导入QuartzCore.framework框架   #import    
二.object.layer.masksToBounds=YES; 
三.object.layer.cornerRadius=XXX; 
[plain] view plaincopyprint? 
UIImageView *testImageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"1.jpg"]];  
[testImageViewsetFrame:CGRectMake(20,20,100,100)];  
testImageView.layer.masksToBounds =YES;   
testImageView.layer.cornerRadius =50/2;   //设置的角度,改变查看效果   
testImageView.layer.borderWidth =5;   //边框宽度   
testImageView.layer.borderColor = [UIColoryellowColor].CGColor;   //边框颜色  
[self.viewaddSubview:testImageView];  
[testImageViewrelease];  

 

5.程序是启动状态时设置屏幕一直亮 
    UIApplication *appDelegate = [UIApplicationsharedApplication];
    appDelegate.idleTimerDisabled =YES;


6.设置UITableViewCell显示子标题 
初始化时:cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier]; 
此处样式应注意,即设置为显示子标题样式,默认样式为不显示子标题,设置完后可用: 
cell.detailTextLabel.text =@"详细标签";    设置子标题


7.给UIView设置阴影效果 
[plain] view plaincopyprint? 
UIView *showView = [[UIViewalloc]initWithFrame:CGRectMake(10,150,100,100)];   
showView.backgroundColor = [UIColorredColor];  
showView.layer.shadowOffset =CGSizeMake(15,5);   
showView.layer.shadowOpacity =0.6;   
showView.layer.shadowColor = [UIColorblackColor].CGColor;  
[self.viewaddSubview:showView];   
[showViewrelease];  


8.设置UITableView选中行数的位置 
[self.tableViewselectRowAtIndexPath:[NSIndexPathindexPathForRow:5inSection:0]animated:NOscrollPosition:UITableViewScrollPositionMiddle];  
//selectRowAtIndexPath设置行数和section   scrollPosition设置滚动到的位置(4项可供选择)


9.UITextField每次操作调用的代理,可根据需求作相应改变 
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

    NSMutableString *newString = [[textField.textmutableCopy]autorelease]; 
    [newStringreplaceCharactersInRange:rangewithString:string];   //得到改变的字符串
}


10.如何用UIColor生成UIImage

[plain] view plaincopyprint?
- (void)viewDidLoad   
{
    [superviewDidLoad];  
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100)];  
    UIImage *image = [self createImageWithColor:[UIColoryellowColor]];   //生成一张黄颜色的图片    
    [imageViewsetImage:image];   
    [self.viewaddSubview:imageView]; 
    [imageViewrelease];  
}    
- (UIImage *) createImageWithColor: (UIColor *) color 
{   
    CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);  
   UIGraphicsBeginImageContext(rect.size);   
   CGContextRef context =UIGraphicsGetCurrentContext();  
   CGContextSetFillColorWithColor(context, [colorCGColor]);  
    CGContextFillRect(context, rect);   
   UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();  
   UIGraphicsEndImageContext();   
    return theImage;   
}   










本文转自 卓行天下  51CTO博客,原文链接:http://blog.51cto.com/9951038/1827817,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
移动开发 前端开发 数据安全/隐私保护
iOS发布证书.p12文件无密码解决办法及导出带密码的新.p12文件方法
iOS发布证书.p12文件无密码解决办法及导出带密码的新.p12文件方法
29 0
|
3月前
|
存储 监控 iOS开发
iOS应用崩溃了,如何通过崩溃手机连接电脑查找日志方法
在iOS应用开发过程中,调试日志和奔溃日志是开发者必不可少的工具。当iOS手机崩溃时,我们可以连接电脑并使用Xcode Console等工具来查看日志。然而,这种方式可能不够方便,并且处理奔溃日志也相当繁琐。克魔助手的出现为开发者带来了极大的便利,本文将详细介绍其功能和使用方法。 克魔助手会提供两种日志,一种是实时的,一种的是崩溃的。(由于崩溃日志的环境很麻烦,目前只展示实时日志操作步骤)
|
3月前
|
存储 iOS开发 开发者
使用克魔助手进行iOS数据抓包和HTTP抓包的方法详解
使用克魔助手进行iOS数据抓包和HTTP抓包的方法详解
47 0
|
3月前
|
安全 编译器 开发工具
​iOS安全加固方法及实现
​iOS安全加固方法及实现
32 0
​iOS安全加固方法及实现
|
4月前
|
iOS开发 开发者
📝 App备案与iOS云管理式证书 ,公钥及证书SHA-1指纹的获取方法
在iOS应用程序开发过程中,进行App备案并获取公钥及证书SHA-1指纹是至关重要的步骤。本文将介绍如何通过appuploader工具获取iOS云管理式证书 Distribution Managed 公钥及证书SHA-1指纹,帮助开发者更好地理解和应用该过程。
|
3月前
|
小程序 前端开发 Android开发
解决小程序中textarea ios端样式不兼容的两种方法
解决小程序中textarea ios端样式不兼容的两种方法
|
1月前
|
Android开发 iOS开发 开发者
App备案-iOS云管理式证书 Distribution Managed 公钥及证书SHA-1指纹的获取方法
App备案-iOS云管理式证书 Distribution Managed 公钥及证书SHA-1指纹的获取方法
97 0
|
1月前
|
安全 编译器 开发工具
​iOS安全加固方法及实现
​iOS安全加固方法及实现
21 0
|
5月前
|
Android开发 iOS开发 开发者
App备案-iOS云管理式证书 Distribution Managed 公钥及证书SHA-1指纹的获取方法
,在appuploder直接复制IOS信息;如果还没有创建证书,请上传正确的P12苹果证书后,系统会自动解析出对应的签名和公钥信息; ——APP备案的原理是基于原有的工信部域名备案系统,如果已经有了域名备案,无需新增备案主体;只需要在之前的域名备案系统里面,新增APP信息,收集的APP信息主要包括APP包名和签名及公钥这3项;——APP备案是属于行政常规主体信息预存,和域名一样,自行决定是否备案。目前国内安卓应用商店是全面要求APP备案的,如果没有APP备案是不能通过审核发布到各大应用商店。——如看了教程,还不清楚怎么获取APP包名、安卓签名、苹果sha1签名、公钥等信息,请联系我们在线客服,
|
6月前
|
网络安全 开发工具 数据安全/隐私保护
如何把ipa文件(iOS安装包)安装到iPhone手机上? 附方法汇总
如何把ipa文件(iOS安装包)安装到iPhone手机上? 附方法汇总