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 <QuartzCore/QuartzCore.h>
二.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;
}
分享到:
相关推荐
iOS开发之UIlabel多行文字自动换行 (自动折行) UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, ...
总之,通过学习本文,读者可以全面了解iOS开发,掌握小程序开发技巧,为成为一名出色的iOS开发者奠定基础。现在,就让我们开始iOS开发的学习之旅吧!相信在这个过程中,你会收获很多宝贵的经验和知识。祝你学习顺利...
IOS开发
很多人就会问学习iOS难不难啊?需要掌握哪些技能呢?有哪些技巧和方法呢?下面本文详细给大家阐述开发技巧与思路。
本文记录了在iOS开发过程中所遇到的小知识点,以及一些技巧,下面话不多说,来看看详细的介绍。 技巧1:UIButton图片与文字默认是左右排列,如何实现右左排列? 解决技巧: button.transform = ...
从C转到ObjectiveC学习的快速指南iOS开发技巧共12页.pdf.zip
之前跟大家分享过一篇《提高iOS开发的小技巧和思路》,但是里面整理的不够全面,通过最近这段时间的整理学习,又整理了一些小技巧和思路分享给大家,下面话不多说了,来看看详细的介绍吧。 一、如何让你的app在后台...
主要给大家分享了一些iOS开发实用的小技巧,这些小技巧在大家开发iOS的时候还是相当实用,有需要的朋友们下面来一起看看吧。
高级篇(14~22章)则非常详细地讲解了iOS应用的架构、iOS应用的测试与调试、可滚动视图的创建、自动宣传和自动调整大小、表格视图的编辑、手势识别、警告、应用程序本地化、日历和事件等高级话题,是iOS开发工程师...
主要为大家详细介绍了iOS开发技巧之自定义相机,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
LayoutGuide这个概念在本人从事iOS开发过程中一直是比较陌生的。直至最近想要了解这个细碎的知识点,就随手查了一下,发现这个概念从iOS7的top/bottom LayoutGuide,到iOS9 UILayoutGuide类的引入,直至最近的iOS11...
高级篇(14~22章)则非常详细地讲解了iOS应用的架构、iOS应用的测试与调试、可滚动视图的创建、自动宣传和自动调整大小、表格视图的编辑、手势识别、警告、应用程序本地化、日历和事件等高级话题,是iOS开发工程师...
高级篇(14~22章)则非常详细地讲解了iOS应用的架构、iOS应用的测试与调试、可滚动视图的创建、自动宣传和自动调整大小、表格视图的编辑、手势识别、警告、应用程序本地化、日历和事件等高级话题,是iOS开发工程师...
iphone初学者开发的小技巧,自己搜集整理,简洁实用
用于iOS开发时候用到的各种小技巧。开发时用的的一些小技巧
主要为大家详细介绍了iOS屏幕适配开发实用技巧,具有一定的参考价值,感兴趣的小伙伴们可以参考一下