ios学习流水账1
1、UIImageview设边框、圆角
需要引QuartzCore/QuartzCore.h>
- //设UIImageView边框
- CALayer *layer = [m_imgView layer];
- [layer setMasksToBounds:YES];
- layer.cornerRadius = 10.0;//设圆角
- [layer setBorderWidth:1];
- [layer setBorderColor:[[UIColor blackColor] CGColor]];
2、bounds属性和frame属性区别
frame指的是:该view在父view坐标系统中的位置和大小.
bounds指的是:该view在本身坐标系统中的位置和大小.
3、导航navigationController设置按钮背景图片
- UIImage *backImage = [UIImage imageNamed:@"ip_bt-back.png"];
- UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, backImage.size.width, backImage.size.height)];
- [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
- [backBtn setBackgroundImage:backImage forState:UIControlStateNormal];
- UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
- self.navigationItem.leftBarButtonItem = leftBtn;
4、ios5加载自定义单元格
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"priceRecordCell";
- //加载nib
- static BOOL nibsRegistered = NO;
- if (!nibsRegistered) {
- UINib *nib = [UINib nibWithNibName:@"PriceRecordCell" bundle:nil];
- [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
- nibsRegistered = YES;
- }
- PriceRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[PriceRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- // Configure the cell...
- cell.nickName.text = @"爱我中华";
- cell.priceLab.text = @"价格 ¥100.00";
- cell.lastTimeLab.text = @"2012-10-15 18:00:08";
- return cell;
- }
5、tableview单元格分割线设置
//不需要分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
6、ios4工程在ios5上运行会出现ARC问题,在Compile Sources 下的Compiler Flags属性中添加-fno-objc-arc,可解决该问题 。
7、UIImageView 上添加点击事件
- UIImageView *imageView =[[UIImageView alloc ]initWithFrame :CGRectMake (100 , 100 , 200 , 200 )];
- imageView. image =[ UIImage imageNamed : @"test.png"];
- //事件可用设置
- imageView. userInteractionEnabled = YES ;
- UITapGestureRecognizer *tap = [[ UITapGestureRecognizer alloc ] initWithTarget : self action : @selector (clickImage)];
- [imageView addGestureRecognizer :tap];
8、ios5 UIView 设圆角
需添加#import <QuartzCore/QuartzCore.h>
centerView.layer.cornerRadius = 6.0f;
9、获取文件路径
- //获取沙盒路径
- NSString *sandboxPath = NSHomeDirectory();
- NSLog(@"sandboxPath :%@",sandboxPath);
- NSString *documentPath = [sandboxPath stringByAppendingPathComponent:@"Documents"];
- NSLog(@"documentPath : %@",documentPath);
- //获取沙盒中的文件目录
- NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //遍历得到的路径
- for (int i=0; i<[documentDirectories count]; i++) {
- NSLog(@"%@",[documentDirectories objectAtIndex:i]);
- }
10、自定义单元格中,如果自定义单元格中有按钮点击事件,不可设置以下属性,会阻塞按钮事件解发。 (2012-10-16)
cell_1.userInteractionEnabled = NO;//单元格不可点击
11、内存过低警告,清除内存
通过消息通知方式提示并清除
- - (id)init{
- //当内存过低时,清空内存
- NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
- [nc addObserver:self selector:@selector(clearCache) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
- }
12、NSBundle可以获取当前程序的资源,得到它,可以获取当前资源中的相关文件,并进行操作。
- //NSBundle获取当前应用资源
- NSBundle *appBundle = [NSBundle mainBundle];
- //bundle得到文件
- NSString *path = [appBundle pathForResource:@"first" ofType:@"png"];
- if (path != nil) {
- NSLog(@"path : %@",path);
- }
- //bundle得到类
- Class class = [appBundle classNamed:@"Test"];
- Test *tinstance = [[class alloc] init];
- [tinstance test];
- //bundle加载xib
- [appBundle loadNibNamed:@"ThirdViewController" owner:self options:nil];
- //bundle中还有很多其它方法,可查api
13、应用状态、状态切换,通过它可了解应用在运行时的各个状态。
常见应用中多种状态:末运行--激活--末激活--后台运行--暂停--激活
- //启动应用时调用
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- //...... NSLog(@"====didFinishLaunchingWithOptions.........%@",NSStringFromSelector(_cmd));
- return YES;
- }
- //按下主窗口按钮时调用(末激活)
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- NSLog(@"====applicationWillResignActive");
- }
- //按下主窗口按钮时调用(后台运行,末激活,5秒后进入暂停)
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- //进行入后运行时,该方法是保存数据的最佳方法
- //[object saveChanges];
- NSLog(@"====applicationDidEnterBackground");
- }
- //按主窗口按钮退出后,再按下应用图标时调用(激活)
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- NSLog(@"====applicationWillEnterForeground");
- }
- //按主窗口按钮退出后,再按下应用图标时调用(激活)
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- NSLog(@"====applicationDidBecomeActive");
- }
- //ios4之前实现该方法,在该方法保存数据最佳
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- NSLog(@"====applicationWillTerminate");
- }
14、沙盒理解
每个ios应用都有自己的应用沙盒(application sandbox),应用沙盒就是文件系统目录,但与文件系统其他部分隔离。应用必须待在自己的沙盒里,其他应用不能访问该沙盒。
15、navigation导航
- //设置Navigation Bar背景
- UIImage *title_bg = [UIImage imageNamed:@"ip_titelbar.png"];
- [self.navigationController.navigationBar setBackgroundImage:title_bg forBarMetrics:UIBarMetricsDefault];
- UIView *_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 360, 40)];
- UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 100, 20)];
- titleLab.text = @"快速竞拍";
- titleLab.textColor = [UIColor redColor];
- titleLab.font = [UIFont fontWithName:@"Arial" size:18];
- titleLab.backgroundColor = [UIColor clearColor];
- [_view addSubview:titleLab];
- resultLab = [[UILabel alloc] initWithFrame:CGRectMake(122, 20, 100, 20)];
- resultLab.backgroundColor = [UIColor clearColor];
- resultLab.font = [UIFont fontWithName:@"Arial" size:14];
- [_view addSubview:resultLab];
- //刷新按钮
- UIButton *refreshBtn = [[UIButton alloc] initWithFrame:CGRectMake(255, 8, 50, 30)];
- [refreshBtn setBackgroundImage:[UIImage imageNamed:@"ip_bt_shuaxin.png"] forState:UIControlStateNormal];
- [refreshBtn addTarget:self action:@selector(refurbish) forControlEvents:UIControlEventTouchUpInside];
- [_view addSubview:refreshBtn];
- self.navigationItem.titleView = _view;
- //显示导航
- // self.navigationController.navigationBarHidden = NO;
16、ipad中UITabBarController添加ViewController。
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
- UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
- DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
- UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
- masterViewController.detailViewController = detailViewController;
- self.splitViewController = [[UISplitViewController alloc] init];
- self.splitViewController.delegate = detailViewController;
- self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
- //首页barTab
- UITabBarController *tabBarController = [[UITabBarController alloc] init];
- self.splitViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"f.jpg"] tag:0];
- //购物车barTab
- CartViewController *cartVC = [[CartViewController alloc] initWithNibName:@"CartViewController" bundle:nil];
- cartVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"购物车" image:[UIImage imageNamed:@"f.jpg"] tag:0];
- //条码购barTab
- BarCodeViewController *barcodeVC = [[BarCodeViewController alloc] initWithNibName:@"BarCodeViewController" bundle:nil];
- barcodeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"条码购" image:[UIImage imageNamed:@"f.jpg"] tag:0];
- //更多barTab
- MoreViewController *moreVC = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];
- moreVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"更多" image:[UIImage imageNamed:@"f.jpg"] tag:0];
- //controller数组
- NSArray *controllers = [NSArray arrayWithObjects:self.splitViewController,cartVC,barcodeVC,moreVC, nil];
- tabBarController.viewControllers = controllers;
- self.window.rootViewController = tabBarController;
- // self.window.rootViewController = self.splitViewController;
- [self.window makeKeyAndVisible];
- return YES;
- }
17、如何获取应用存放文件根路径:
- //根路径
- NSString *homePath = [[NSBundle mainBundle] executablePath];
- NSArray *strings = [homePath componentsSeparatedByString: @"/"];
- NSString *executableName = [strings objectAtIndex:[strings count]-1];
- NSString *baseDirectory = [homePath substringToIndex:
- [homePath length]-[executableName length]-1];
- NSString *fileName = [NSString stringWithFormat:@"%@/test.txt",baseDirectory];
- NSLog(@"filePath: %@",fileName);
18、block类似匿名函数
以为例子:
- static int outA = 8;
- static NSString *c=@"";
- int(^myPtr)(int,NSString *)=^(int a,NSString *b){
- c=b;
- return outA+a;
- };
- outA = 5;//改变outA
- int result = myPtr(2,@"test");//结果为10,outA是复制的,后面改变outA无效
- NSLog(@"result : %i",result);
19、performSelector的应用,它可直接调用实例的方法,能延迟执行方法时间。
- - (void) test:(NSString *) str;
- - (void) test:(NSString *) str{
- NSLog(@"you input is : %@",str);
- }
- //调用方法
- [self performSelector:@selector(test:) withObject:@"dwen"];
- [self performSelector:@selector(test:) withObject:@"wen" afterDelay:2.0f];//两秒后执行
20、UIButton中addTarget中传参问题,该事件可以通过setTag方法进行传整数。
- UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, height)];
- //action参数中写入事件执行方法
- [button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
- //在button的tag中添加你需要传递的参数
- [button setTag:100];
- //action方法
- -(void)action:(id)sender{
- int i = [sender tag];
- }
21、沙盒中包含三个文件夹,Documents 、Library和tmp
- //获取Documents目录
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
- NSString *documentDirectory = [paths objectAtIndex:0];
- NSLog(@"%@",documentDirectory);
- //获取当前应用中文件路径
- NSString *filename = [documentDirectory stringByAppendingPathComponent:@"w12122.jpg"];
- NSLog(@"%@",filename);
- //获取tmp目录
- NSString *tempPath = NSTemporaryDirectory();
- NSString *tempFile = [tempPath stringByAppendingPathComponent:@"w12122.jpg"];
- NSLog(@"tempFile :%@",tempFile);
22、NSString截取字符串
NSString *str = @"B12121.jpg";
NSRange range = [str rangeOfString:@"."];
NSLog(@"%i",range.location);
NSLog(@"%@",[str substringToIndex:range.location]);
23、UINavigationBar
- //创建导航栏集合
- UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
- //创建一个左边按钮
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回"
- style:UIBarButtonItemStyleBordered
- target:self
- action:@selector(back)];
- //设置导航栏内容
- [navigationItem setTitle:@"拍品列表"];
- //把导航栏集合添加入导航栏中,设置动画关闭
- [navigationBar pushNavigationItem:navigationItem animated:NO];
- //把左右两个按钮添加入导航栏集合中
- [navigationItem setLeftBarButtonItem:leftButton];
24、在navigationController中添加右边多个按钮。效果图:

代码如下:
- //添加导航右边按钮
- UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
- [tools setTintColor:[self.navigationController.navigationBar tintColor]];
- [tools setAlpha:[self.navigationController.navigationBar alpha]];
- NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:1];
- UIBarButtonItem *firstBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showSpecial)];
- [buttons addObject:firstBtn];
- [tools setItems:buttons animated:NO];
- UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools];
- self.navigationItem.rightBarButtonItem = myBtn;
25、循环删除uiview
- for (UIView *subview in scrollView.subviews) {
- if ([subview isKindOfClass:[CatalogView class]]) {
- [subview removeFromSuperview];
- }
- }
26、ios4以前内存管理

00
ios学习流水账1的更多相关文章
- ios学习流水账2
1.UISearchBar自定义背景.取消按钮中文设置 UISearchBar *seachBar=[[UISearchBar alloc] init]; //修改搜索框背景 seachBar.bac ...
- iOS学习-压缩图片(改变图片的宽高)
压缩图片,图片的大小与我们期望的宽高不一致时,我们可以将其处理为我们想要的宽高. 传入想要修改的图片,以及新的尺寸 -(UIImage*)imageWithImage:(UIImage*)image ...
- 【原】iOS学习之事件处理的原理
在iOS学习23之事件处理中,小编详细的介绍了事件处理,在这里小编叙述一下它的相关原理 1.UITouch对象 在触摸事件的处理方法中都会有一个存放着UITouch对象的集合,这个参数有什么用呢? ( ...
- iOS学习笔记——AutoLayout的约束
iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...
- 【原】iOS学习47之第三方-FMDB
将 CocoaPods 安装后,按照 CocoaPods 的使用说明就可以将 FMDB 第三方集成到工程中,具体请看博客iOS学习46之第三方CocoaPods的安装和使用(通用方法) 1. FMDB ...
- iOS学习路线图
一.iOS学习路线图 二.iOS学习路线图--视频篇 阶 段 学完后目标 知识点 配套学习资源(笔记+源码+PPT) 密码 基础阶段 学习周期:24天 学习后目标: ...
- 黑苹果-IOS学习的开始
深知安装黑苹果的不易,在这里写一下关于我的Thinkpad E430c安装黑苹果教程(Mac版本:Yosemite 10.10.4),希望能够帮助有需要的朋友. 首先贴上我的电脑配置报表: ----- ...
- iOS 学习资源
这份学习资料是为 iOS 初学者所准备的, 旨在帮助 iOS 初学者们快速找到适合自己的学习资料, 节省他们搜索资料的时间, 使他们更好的规划好自己的 iOS 学习路线, 更快的入门, 更准确的定位的 ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
随机推荐
- 九宫重排_康拓展开_bfs
历届试题 九宫重排 时间限制:1.0s 内存限制:256.0MB 问题描述 如下面第一个图的九宫格中,放着 1~8 的数字卡片,还有一个格子空着.与空格子相邻的格子中的卡片可 ...
- SQL查询oracle的nclob字段
使用CONTAINS关键字查询NCLOB字段 SELECT FORMATTED_MESSAGE FROM TBL_LOG WHERE CONTAINS(FORMATTED_ME ...
- 第十六篇:django基础
本篇内容 创建程序 程序目录 流程介绍 login实例 一.创建程序 命令行: django-admin startproject sitename. 常用命令: python manage.py r ...
- P4113 [HEOI2012]采花
题目描述 萧薰儿是古国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花. 花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于 ...
- Codeforces - 220B Little Elephant and Array(莫队模板题)
题意: m次查询.每次查询范围[L,R]中出现次数等于该数字的数字个数. 题解: 由于分块,在每次询问中,同一块时l至多移动根号n,从一块到另一块也是最多2倍根号n.对于r,每个块中因为同一块是按y排 ...
- Yii2.0 使用createcommand从数据库查询出来的int类型变成了string型
在给客户端写接口文档时,会给每个返回的字段标上数据类型,客户端会根据标注的类型来解析数据,如果标注的类型错误,会导致客户端解析出错,造成崩溃. 一直以来我都是用的Yii进行项目的开发,之前使用Yii1 ...
- Codeforces Round #462 (Div. 2)
这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...
- Educational Codeforces Round 42 (Rated for Div. 2) B
B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...
- xen hypercall 的应用层实现
一句话描述: xen hypercall 在应用层的实现,最终都变成对 /proc/xen/privcmd 的 ioctl 系统调用 我们知道,xen 在应用层最上层的接口是 libxl , 基本上 ...
- FileInputStream读取文件&FileOutputStream写入文件
概念摘自:http://jingyan.baidu.com/article/5552ef473ab5f2518ffbc98e.html Java的流式输入输出建立在4个抽象类的基础上:InputStr ...