1、UIImageview设边框、圆角

需要引QuartzCore/QuartzCore.h>

  1. //设UIImageView边框
  2. CALayer *layer = [m_imgView layer];
  3. [layer setMasksToBounds:YES];
  4. layer.cornerRadius = 10.0;//设圆角
  5. [layer setBorderWidth:1];
  6. [layer setBorderColor:[[UIColor blackColor] CGColor]];

2、bounds属性和frame属性区别

frame指的是:该view在父view坐标系统中的位置和大小.

bounds指的是:该view在本身坐标系统中的位置和大小.

3、导航navigationController设置按钮背景图片

  1. UIImage *backImage = [UIImage imageNamed:@"ip_bt-back.png"];
  2. UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, backImage.size.width, backImage.size.height)];
  3. [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
  4. [backBtn setBackgroundImage:backImage forState:UIControlStateNormal];
  5. UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
  6. self.navigationItem.leftBarButtonItem = leftBtn;

4、ios5加载自定义单元格

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. static NSString *CellIdentifier = @"priceRecordCell";
  4. //加载nib
  5. static BOOL nibsRegistered = NO;
  6. if (!nibsRegistered) {
  7. UINib *nib = [UINib nibWithNibName:@"PriceRecordCell" bundle:nil];
  8. [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
  9. nibsRegistered = YES;
  10. }
  11. PriceRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  12. if (cell == nil) {
  13. cell = [[PriceRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  14. }
  15. // Configure the cell...
  16. cell.nickName.text = @"爱我中华";
  17. cell.priceLab.text = @"价格 ¥100.00";
  18. cell.lastTimeLab.text = @"2012-10-15 18:00:08";
  19. return cell;
  20. }

5、tableview单元格分割线设置

//不需要分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

6、ios4工程在ios5上运行会出现ARC问题,在Compile Sources 下的Compiler Flags属性中添加-fno-objc-arc,可解决该问题 。

7、UIImageView 上添加点击事件

  1. UIImageView *imageView =[[UIImageView alloc ]initWithFrame :CGRectMake (100 , 100 , 200 , 200 )];
  2. imageView. image =[ UIImage imageNamed : @"test.png"];
  3. //事件可用设置
  4. imageView. userInteractionEnabled = YES ;
  5. UITapGestureRecognizer *tap = [[ UITapGestureRecognizer alloc ] initWithTarget : self action : @selector (clickImage)];
  6. [imageView addGestureRecognizer :tap];

8、ios5 UIView 设圆角

需添加#import <QuartzCore/QuartzCore.h>

centerView.layer.cornerRadius = 6.0f;

9、获取文件路径

  1. //获取沙盒路径
  2. NSString *sandboxPath = NSHomeDirectory();
  3. NSLog(@"sandboxPath :%@",sandboxPath);
  4. NSString *documentPath = [sandboxPath stringByAppendingPathComponent:@"Documents"];
  5. NSLog(@"documentPath : %@",documentPath);
  6. //获取沙盒中的文件目录
  7. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  8. //遍历得到的路径
  9. for (int i=0; i<[documentDirectories count]; i++) {
  10. NSLog(@"%@",[documentDirectories objectAtIndex:i]);
  11. }

10、自定义单元格中,如果自定义单元格中有按钮点击事件,不可设置以下属性,会阻塞按钮事件解发。 (2012-10-16)

cell_1.userInteractionEnabled = NO;//单元格不可点击

11、内存过低警告,清除内存

通过消息通知方式提示并清除

  1. - (id)init{
  2. //当内存过低时,清空内存
  3. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  4. [nc addObserver:self selector:@selector(clearCache) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
  5. }

12、NSBundle可以获取当前程序的资源,得到它,可以获取当前资源中的相关文件,并进行操作。

  1. //NSBundle获取当前应用资源
  2. NSBundle *appBundle = [NSBundle mainBundle];
  3. //bundle得到文件
  4. NSString *path = [appBundle pathForResource:@"first" ofType:@"png"];
  5. if (path != nil) {
  6. NSLog(@"path : %@",path);
  7. }
  8. //bundle得到类
  9. Class class = [appBundle classNamed:@"Test"];
  10. Test *tinstance = [[class alloc] init];
  11. [tinstance test];
  12. //bundle加载xib
  13. [appBundle loadNibNamed:@"ThirdViewController" owner:self options:nil];
  14. //bundle中还有很多其它方法,可查api

13、应用状态、状态切换,通过它可了解应用在运行时的各个状态。

常见应用中多种状态:末运行--激活--末激活--后台运行--暂停--激活

  1. //启动应用时调用
  2. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  3. {
  4. //......    NSLog(@"====didFinishLaunchingWithOptions.........%@",NSStringFromSelector(_cmd));
  5. return YES;
  6. }
  7. //按下主窗口按钮时调用(末激活)
  8. - (void)applicationWillResignActive:(UIApplication *)application
  9. {
  10. NSLog(@"====applicationWillResignActive");
  11. }
  12. //按下主窗口按钮时调用(后台运行,末激活,5秒后进入暂停)
  13. - (void)applicationDidEnterBackground:(UIApplication *)application
  14. {
  15. //进行入后运行时,该方法是保存数据的最佳方法
  16. //[object saveChanges];
  17. NSLog(@"====applicationDidEnterBackground");
  18. }
  19. //按主窗口按钮退出后,再按下应用图标时调用(激活)
  20. - (void)applicationWillEnterForeground:(UIApplication *)application
  21. {
  22. NSLog(@"====applicationWillEnterForeground");
  23. }
  24. //按主窗口按钮退出后,再按下应用图标时调用(激活)
  25. - (void)applicationDidBecomeActive:(UIApplication *)application
  26. {
  27. NSLog(@"====applicationDidBecomeActive");
  28. }
  29. //ios4之前实现该方法,在该方法保存数据最佳
  30. - (void)applicationWillTerminate:(UIApplication *)application
  31. {
  32. NSLog(@"====applicationWillTerminate");
  33. }

14、沙盒理解

每个ios应用都有自己的应用沙盒(application sandbox),应用沙盒就是文件系统目录,但与文件系统其他部分隔离。应用必须待在自己的沙盒里,其他应用不能访问该沙盒。

15、navigation导航

  1. //设置Navigation Bar背景
  2. UIImage *title_bg = [UIImage imageNamed:@"ip_titelbar.png"];
  3. [self.navigationController.navigationBar setBackgroundImage:title_bg forBarMetrics:UIBarMetricsDefault];
  4. UIView *_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 360, 40)];
  5. UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 100, 20)];
  6. titleLab.text = @"快速竞拍";
  7. titleLab.textColor = [UIColor redColor];
  8. titleLab.font = [UIFont fontWithName:@"Arial" size:18];
  9. titleLab.backgroundColor = [UIColor clearColor];
  10. [_view addSubview:titleLab];
  11. resultLab = [[UILabel alloc] initWithFrame:CGRectMake(122, 20, 100, 20)];
  12. resultLab.backgroundColor = [UIColor clearColor];
  13. resultLab.font = [UIFont fontWithName:@"Arial" size:14];
  14. [_view addSubview:resultLab];
  15. //刷新按钮
  16. UIButton *refreshBtn = [[UIButton alloc] initWithFrame:CGRectMake(255, 8, 50, 30)];
  17. [refreshBtn setBackgroundImage:[UIImage imageNamed:@"ip_bt_shuaxin.png"] forState:UIControlStateNormal];
  18. [refreshBtn addTarget:self action:@selector(refurbish) forControlEvents:UIControlEventTouchUpInside];
  19. [_view addSubview:refreshBtn];
  20. self.navigationItem.titleView = _view;
  21. //显示导航
  22. //    self.navigationController.navigationBarHidden = NO;

16、ipad中UITabBarController添加ViewController。

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  4. // Override point for customization after application launch.
  5. MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
  6. UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
  7. DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
  8. UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
  9. masterViewController.detailViewController = detailViewController;
  10. self.splitViewController = [[UISplitViewController alloc] init];
  11. self.splitViewController.delegate = detailViewController;
  12. self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
  13. //首页barTab
  14. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  15. self.splitViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"f.jpg"] tag:0];
  16. //购物车barTab
  17. CartViewController *cartVC = [[CartViewController alloc] initWithNibName:@"CartViewController" bundle:nil];
  18. cartVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"购物车" image:[UIImage imageNamed:@"f.jpg"] tag:0];
  19. //条码购barTab
  20. BarCodeViewController *barcodeVC = [[BarCodeViewController alloc] initWithNibName:@"BarCodeViewController" bundle:nil];
  21. barcodeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"条码购" image:[UIImage imageNamed:@"f.jpg"] tag:0];
  22. //更多barTab
  23. MoreViewController *moreVC = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];
  24. moreVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"更多" image:[UIImage imageNamed:@"f.jpg"] tag:0];
  25. //controller数组
  26. NSArray *controllers = [NSArray arrayWithObjects:self.splitViewController,cartVC,barcodeVC,moreVC, nil];
  27. tabBarController.viewControllers = controllers;
  28. self.window.rootViewController = tabBarController;
  29. //    self.window.rootViewController = self.splitViewController;
  30. [self.window makeKeyAndVisible];
  31. return YES;
  32. }

17、如何获取应用存放文件根路径:

  1. //根路径
  2. NSString *homePath = [[NSBundle mainBundle] executablePath];
  3. NSArray *strings = [homePath componentsSeparatedByString: @"/"];
  4. NSString *executableName  = [strings objectAtIndex:[strings count]-1];
  5. NSString *baseDirectory = [homePath substringToIndex:
  6. [homePath length]-[executableName length]-1];
  7. NSString *fileName = [NSString stringWithFormat:@"%@/test.txt",baseDirectory];
  8. NSLog(@"filePath: %@",fileName);

18、block类似匿名函数

以为例子:

  1. static int outA = 8;
  2. static NSString *c=@"";
  3. int(^myPtr)(int,NSString *)=^(int a,NSString *b){
  4. c=b;
  5. return outA+a;
  6. };
  7. outA = 5;//改变outA
  8. int result = myPtr(2,@"test");//结果为10,outA是复制的,后面改变outA无效
  9. NSLog(@"result : %i",result);

19、performSelector的应用,它可直接调用实例的方法,能延迟执行方法时间。

  1. - (void) test:(NSString *) str;
  2. - (void) test:(NSString *) str{
  3. NSLog(@"you input is : %@",str);
  4. }
  5. //调用方法
  6. [self performSelector:@selector(test:) withObject:@"dwen"];
  7. [self performSelector:@selector(test:) withObject:@"wen" afterDelay:2.0f];//两秒后执行

20、UIButton中addTarget中传参问题,该事件可以通过setTag方法进行传整数。

  1. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  2. //action参数中写入事件执行方法
  3. [button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
  4. //在button的tag中添加你需要传递的参数
  5. [button setTag:100];
  6. //action方法
  7. -(void)action:(id)sender{
  8. int i = [sender tag];
  9. }

 

21、沙盒中包含三个文件夹,Documents 、Library和tmp

  1. //获取Documents目录
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
  3. NSString *documentDirectory = [paths objectAtIndex:0];
  4. NSLog(@"%@",documentDirectory);
  5. //获取当前应用中文件路径
  6. NSString *filename = [documentDirectory stringByAppendingPathComponent:@"w12122.jpg"];
  7. NSLog(@"%@",filename);
  8. //获取tmp目录
  9. NSString *tempPath = NSTemporaryDirectory();
  10. NSString *tempFile = [tempPath stringByAppendingPathComponent:@"w12122.jpg"];
  11. NSLog(@"tempFile :%@",tempFile);

 

22、NSString截取字符串

NSString *str = @"B12121.jpg";
        NSRange range = [str rangeOfString:@"."];
        NSLog(@"%i",range.location);
        NSLog(@"%@",[str substringToIndex:range.location]);

 23、UINavigationBar

  1. //创建导航栏集合
  2. UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
  3. //创建一个左边按钮
  4. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回"
  5. style:UIBarButtonItemStyleBordered
  6. target:self
  7. action:@selector(back)];
  8. //设置导航栏内容
  9. [navigationItem setTitle:@"拍品列表"];
  10. //把导航栏集合添加入导航栏中,设置动画关闭
  11. [navigationBar pushNavigationItem:navigationItem animated:NO];
  12. //把左右两个按钮添加入导航栏集合中
  13. [navigationItem setLeftBarButtonItem:leftButton];

24、在navigationController中添加右边多个按钮。效果图:


 代码如下:

  1. //添加导航右边按钮
  2. UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
  3. [tools setTintColor:[self.navigationController.navigationBar tintColor]];
  4. [tools setAlpha:[self.navigationController.navigationBar alpha]];
  5. NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:1];
  6. UIBarButtonItem *firstBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showSpecial)];
  7. [buttons addObject:firstBtn];
  8. [tools setItems:buttons animated:NO];
  9. UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools];
  10. self.navigationItem.rightBarButtonItem = myBtn;

25、循环删除uiview

  1. for (UIView *subview in scrollView.subviews) {
  2. if ([subview isKindOfClass:[CatalogView class]]) {
  3. [subview removeFromSuperview];
  4. }
  5. }

26、ios4以前内存管理 

00

ios学习流水账1的更多相关文章

  1. ios学习流水账2

    1.UISearchBar自定义背景.取消按钮中文设置 UISearchBar *seachBar=[[UISearchBar alloc] init]; //修改搜索框背景 seachBar.bac ...

  2. iOS学习-压缩图片(改变图片的宽高)

    压缩图片,图片的大小与我们期望的宽高不一致时,我们可以将其处理为我们想要的宽高. 传入想要修改的图片,以及新的尺寸 -(UIImage*)imageWithImage:(UIImage*)image ...

  3. 【原】iOS学习之事件处理的原理

    在iOS学习23之事件处理中,小编详细的介绍了事件处理,在这里小编叙述一下它的相关原理 1.UITouch对象 在触摸事件的处理方法中都会有一个存放着UITouch对象的集合,这个参数有什么用呢? ( ...

  4. iOS学习笔记——AutoLayout的约束

    iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...

  5. 【原】iOS学习47之第三方-FMDB

    将 CocoaPods 安装后,按照 CocoaPods 的使用说明就可以将 FMDB 第三方集成到工程中,具体请看博客iOS学习46之第三方CocoaPods的安装和使用(通用方法) 1. FMDB ...

  6. iOS学习路线图

    一.iOS学习路线图   二.iOS学习路线图--视频篇       阶 段 学完后目标 知识点 配套学习资源(笔记+源码+PPT) 密码 基础阶段 学习周期:24天       学习后目标:    ...

  7. 黑苹果-IOS学习的开始

    深知安装黑苹果的不易,在这里写一下关于我的Thinkpad E430c安装黑苹果教程(Mac版本:Yosemite 10.10.4),希望能够帮助有需要的朋友. 首先贴上我的电脑配置报表: ----- ...

  8. iOS 学习资源

    这份学习资料是为 iOS 初学者所准备的, 旨在帮助 iOS 初学者们快速找到适合自己的学习资料, 节省他们搜索资料的时间, 使他们更好的规划好自己的 iOS 学习路线, 更快的入门, 更准确的定位的 ...

  9. iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

    http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...

随机推荐

  1. GDI+实现双缓冲绘图方法一

    private void Form5_MouseMove(object sender, MouseEventArgs e) { int intOX = rectDrawArea.X; int intO ...

  2. 设置EntityFramework中decimal类型数据精度问题(EF默认将只会保留到2为精度)

    原文:设置EntityFramework中decimal类型数据精度 EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. .19990将会 ...

  3. J2EE的十三个技术——EJB之消息驱动JMS

    JMS--Java Message Service JAVA的消息服务,消息可实现两端通信. 用于访问面向消息中间件的标准api,他提供与厂商无关的访问方法,以访问消息收发服务. 特点:即使其中一方不 ...

  4. 【Luogu】P3228数列(数学题)

    题目链接 考虑我们把所有的增加量拿出来做成一个序列b. 那么在所有n中开头中$1~\sum\limits_{i=1}^{k-1}b[i]$是合法的 也就是说我们枚举所有b[i],然后答案就是$n*m^ ...

  5. [CF463D]Gargari and Permutations

    题目大意:给你$k(2\leqslant k\leqslant5)$个$1\sim n(n\leqslant10^3)$的排列,求它们的最长子序列 题解:将$k$个排列中每个元素的位置记录下来.如果是 ...

  6. 洛谷 P1136 迎接仪式 解题报告

    P1136 迎接仪式 题目描述 LHX教主要来X市指导OI学习工作了.为了迎接教主,在一条道路旁,一群Orz教主er穿着文化衫站在道路两旁迎接教主,每件文化衫上都印着大字.一旁的Orzer依次摆出&q ...

  7. 3.Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件

    先说和虚拟化技术的区别 难道虚拟技术就做不到吗? 不不不,虚拟技术也可以做到,但是会有一定程度的性能损失,灵活度也会下降.容器技术不是模仿硬件层次,而是 在Linux内核里使用cgroup和names ...

  8. js判断变量类型,类型转换,

    1.typeof 操作符 主要检测基础数据类型 var a="zhangqian"; var b=true; ; var d; var e=null; var f=new Obje ...

  9. 用MysQL语句怎么进行远程连接数据库

    一.连接远程数据库: 1.显示密码如:MySQL 连接远程数据库(192.168.2.115),端口“3306”,用户名为“root”,密码“root” C: -u root -proot (注意第一 ...

  10. 解方程(NOIP2014)Warning!(前方高能!!)

    原题传送门 一看这不是水题嘛. 枚举+乱搞..特别容易.... 然后a[i]取值范围出现了 当当当当~:|a[i]|<=10^10000!!!!! 我去,这是什么鬼.. 高精度? 然后默默算了算 ...