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 ...
随机推荐
- Java 中xml解析
1.String 字符串保持到txt文件 String xml ="abcdefghijk"; FileWriter fw = null; File f = new File(&q ...
- SQL 唯一标识 写法
创建唯一标识的方法~16位唯一标识 SELECT LTRIM(STR(CONVERT(varchar(100), GETDATE(), 112)))+right(cast(power(10,6) as ...
- Axios & Interceptors & Serialization & CORS & cookie
Axios https://github.com/axios/axios#config-defaults Global axios defaults axios.defaults.baseURL = ...
- 使用python读取mysql数据库并进行数据的操作
(一)环境的配置 使用python调用mysql数据库要引进一些库. 目前我使用的python版本是python3.6.引进库为pymysql 其他对应的库可以有以下选择: mysqldb,oursq ...
- powerdesign相关
1.安装程序和汉化放百度云了 2.打印错误处理 http://jingyan.baidu.com/article/c45ad29cd84e4b051753e2c3.html 3.导出sql http: ...
- java 复习整理(四 String类详解)
String 类详解 StringBuilder与StringBuffer的功能基本相同,不同之处在于StringBuilder是非线程安全的,而StringBuffer是线程安全的,因此效率上S ...
- css垂直居中的几种方式
1. 对于可以一行处理的 设置 height:apx; line-height:apx; 2.对于一段文字(会多行显示的) ->2.1如果是可以设置一个固定高度的 ...
- C语言.c和.h
简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析阶段 3.编译阶段,首先编译成 ...
- 【ZOJ4061】Magic Multiplication(构造)
题意:定义一个新运算为两个数A,B上每一位相乘,然后顺次接在一起,现在给定结果C和原来两个数字的长度,要求恢复成原来的数字A,B 若有多解输出A字典序最小的,A相同输出B字典序最小的,无解输出Impo ...
- Linux Mint---开启桌面三维特效
其实系统默认已经安装好了compiz,我们只需要切换就可以了 menu->control center->desktop setting->window 开启compiz的时候,由于 ...