http://mobile.51cto.com/hot-410417.htm

退回输入键盘:

  1. - (BOOL) textFieldShouldReturn:(id)textField{
  2. [textField  resignFirstResponder];
  3. }

CGRect

CGPoint & CGSize

  1. CGPoint aPoint = CGPointMake(x, y);    CGSize aSize = CGSizeMake(width, height);

设置透明度

  1. [myView setAlpha:value];   (0.0 < value < 1.0)

设置背景色

  1. [myView setBackgroundColor:[UIColor redColor]];
  2. (blackColor;darkGrayColor;lightGrayColor;whiteColor;grayColor; redColor; greenColor; blueColor; cyanColor;yellowColor;magentaColor;
  3. orangeColor;purpleColor;brownColor; clearColor; )

自定义颜色:

  1. UIColor *newColor = [[UIColor alloc] initWithRed:(float) green:(float) blue:(float) alpha:(float)];      0.0~1.0

宽度和高度

1
768X1024     1024X768    状态栏高 20 像素高   导航栏 工具栏 44像素高

隐藏状态栏:

  1. [[UIApplication shareApplication] setStatusBarHidden: YES animated:NO]

横屏:

  1. [[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].
  2. orientation == UIInterfaceOrientationLandscapeLeft
  3. window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];全屏

自动适应父视图大小:

  1. aView.autoresizingSubviews = YES;
  2. aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

定义按钮

  1. UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  2. [scaleUpButton setTitle:@"放 大"forState:UIControlStateNormal];
  3. scaleUpButton.frame = CGRectMake(40, 420, 100, 40);
  4. [scaleUpButton addTarget:self action:@selector(scaleUp) forControlEvents:UIControlEventTouchUpInside];

设置视图背景图片

  1. UIImageView *aView;
  2. [aView setImage:[UIImage imageNamed:@”name.png”]];
  3. view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image1.png"]];
  4. UISlider *slider = (UISlider *) sender;
  5. NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
  6. label.text = newText;

活动表单 <UIActionSheetDelegate>

  1. - (IBActive) someButtonPressed:(id) sender
  2. {
  3. UIActionSheet *actionSheet = [[UIActionSheet alloc]
  4. initWithTitle:@”Are you sure?”
  5. delegate:self
  6. cancelButtonTitle:@”No way!”
  7. destructiveButtonTitle:@”Yes, I’m Sure!”
  8. otherButtonTitles:nil];
  9. [actionSheet showInView:self.view];
  10. [actionSheet release];
  11. }

警告视图 <UIAlertViewDelegate>

  1. - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
  2. {
  3. if(buttonIndex != [actionSheet cancelButtonIndex])
  4. {
  5. NSString *message = [[NSString alloc] initWithFormat:@”You can
  6. breathe easy, everything went OK.”];
  7. UIAlertView *alert = [[UIAlertView alloc]
  8. initWithTitle:@”Something was done”
  9. message:message
  10. delegate:self
  11. cancelButtonTitle:@”OK”
  12. otherButtonTitles:nil];
  13. [alert show];
  14. [alert release];
  15. [message release];
  16. }
  17. }

动画效果

  1. -(void)doChange:(id)sender
  2. {
  3. if(view2 == nil)
  4. {
  5. [self loadSec];
  6. }
  7. [UIView beginAnimations:nil context:NULL];
  8. [UIView setAnimationDuration:1];
  9. [UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];
  10. if([view1 superview]!= nil)
  11. {
  12. [view1 removeFromSuperview];
  13. [self.view addSubview:view2];
  14. }else{
  15. [view2 removeFromSuperview];
  16. [self.view addSubview:view1];
  17. }
  18. [UIView commitAnimations];
  19. }

Table View <UITableViewDateSource>

  1. #pragma mark -
  2. #pragma mark Table View Data Source Methods
  3. //指定分区中的行数,默认为1
  4. - (NSInteger)tableView:(UITableView *)tableView
  5. numberOfRowsInSection:(NSInteger)section
  6. {
  7. return[self.listDatacount];
  8. }
  9. //设置每一行cell显示的内容
  10. - (UITableViewCell *)tableView:(UITableView *)tableView
  11. cellForRowAtIndexPath:(NSIndexPath *)indexPath
  12. {
  13. staticNSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
  14. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
  15. if(cell == nil) {
  16. cell = [[[UITableViewCell alloc]
  17. initWithStyle:UITableViewCellStyleSubtitle
  18. reuseIdentifier:SimpleTableIndentifier]
  19. autorelease];
  20. }
  21. UIImage *image = [UIImage imageNamed:@"13.gif"];
  22. cell.imageView.image = image;
  23. NSUInteger row = [indexPath row];
  24. cell.textLabel.text = [listData objectAtIndex:row];
  25. cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
  26. if(row < 5)
  27. cell.detailTextLabel.text = @"Best friends";
  28. else
  29. cell.detailTextLabel.text = @"friends";
  30. returncell;
  31. }

图像:如果设置图像,则它显示在文本的左侧

文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签)

详细文本标签:这是单元的辅助文本,通常用作解释性说明或标签

  1. UITableViewCellStyleSubtitle
  2. UITableViewCellStyleDefault
  3. UITableViewCellStyleValue1
  4. UITableViewCellStyleValue2
  5. <UITableViewDelegate>
  6. #pragma mark -
  7. #pragma mark Table View Delegate Methods
  8. //把每一行缩进级别设置为其行号
  9. - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
  10. {
  11. NSUInteger row = [indexPath row];
  12. returnrow;
  13. }
  14. //获取传递过来的indexPath值
  15. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  16. {
  17. NSUInteger row = [indexPath row];
  18. if(row == 0)
  19. returnnil;
  20. returnindexPath;
  21. }
  22. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  23. {
  24. NSUInteger row = [indexPath row];
  25. NSString *rowValue = [listData objectAtIndex:row];
  26. NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];
  27. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected"
  28. message:message
  29. delegate:nil
  30. cancelButtonTitle:@"Yes, I did!"
  31. otherButtonTitles:nil];
  32. [alert show];
  33. [alert release];
  34. [message release];
  35. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  36. }
  37. //设置行的高度
  38. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  39. {
  40. return40;
  41. }

随机数的使用

  1. 头文件的引用
  2. #import <time.h>
  3. #import <mach/mach_time.h>
  4. srandom()的使用
  5. srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF));
  6. 直接使用 random() 来调用随机数

在UIImageView 中旋转图像

  1. float rotateAngle = M_PI;
  2. CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);
  3. imageView.transform = transform;

以上代码旋转imageView, 角度为rotateAngle, 方向可以自己测试哦!

在Quartz中如何设置旋转点

  1. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];
  2. imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);

这个是把旋转点设置为底部中间。记住是在QuartzCore.framework中才得到支持。

创建.plist文件并存储

  1. NSString *errorDesc; //用来存放错误信息
  2. NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4];//NSDictionary, NSData等文件可以直接转化为plist文件
  3. NSDictionary *innerDict;
  4. NSString *name;
  5. Player *player;
  6. NSInteger saveIndex;
  7. for(int i = 0; i < [playerArraycount]; i++) {
  8. player = nil;
  9. player = [playerArray objectAtIndex:i];
  10. if(player == nil)
  11. break;
  12. name = player.playerName;// This “Player1″ denotes the player name could also be the computer name
  13. innerDict = [self getAllNodeInfoToDictionary:player];
  14. [rootObj setObject:innerDict forKey:name];// This “Player1″ denotes the person who start this game
  15. }
  16. player = nil;
  17. NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];

最后2行可以忽略,只是给rootObj添加一点内容。这个plistData为创建好的plist文件,用其writeToFile方法就可以写成文件。下面是代码:

  1. 17  /*得到移动设备上的文件存放位置*/
  2. NSString *documentsPath = [self getDocumentsDirectory];
  3. NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
  4. /*存文件*/
  5. if(plistData) {
  6. [plistData writeToFile:savePath atomically:YES];
  7. }
  8. else{
  9. NSLog(errorDesc);
  10. [errorDesc release];
  11. }
  12. - (NSString *)getDocumentsDirectory {
  13. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  14. return[paths objectAtIndex:0];
  15. }

读取plist文件并转化为NSDictionary

  1. NSString *documentsPath = [self getDocumentsDirectory];
  2. NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
  3. NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];

读取一般性文档文件

  1. NSString *tmp;
  2. NSArray *lines;/*将文件转化为一行一行的*/
  3. lines = [[NSString    stringWithContentsOfFile:@"testFileReadLines.txt"]
  4. componentsSeparatedByString:@”\n”];
  5. NSEnumerator *nse = [lines objectEnumerator];
  6. // 读取<>里的内容
  7. while(tmp = [nse nextObject]) {
  8. NSString *stringBetweenBrackets = nil;
  9. NSScanner *scanner = [NSScanner scannerWithString:tmp];
  10. [scanner scanUpToString:@"<"intoString:nil];
  11. [scanner scanString:@"<"intoString:nil];
  12. [scanner scanUpToString:@">"intoString:&stringBetweenBrackets];
  13. NSLog([stringBetweenBrackets description]);
  14. }

对于读写文件,还有补充,暂时到此。随机数和文件读写在游戏开发中经常用到。所以把部分内容放在这,以便和大家分享,也当记录,便于查找。

隐藏NavigationBar

  1. [self.navigationController setNavigationBarHidden:YES animated:YES];

在想隐藏的ViewController中使用就可以了。

如果无法保证子类行为的一致性,那么就用委托

  1. If the subClass cann’t keep with superClass,use delegate rather than inheritance.

屏幕上看到的,都是UIVew

  1. Everything you see on Screen is UIView.

如果对性能要求高,慎用Interface Build

  1. if application’s performance is important,be discreet for the interface build.

copy是创建,retain是引用

  1. the copy operation is create a new one,but the retain operation is just a reference.

alloc需要release,convenient不需要release

  1. alloc method need corresponding release method,but convenient method not.

加载到NSArray/NSMutableArray里的对象,不需要负责release

  1. The objects added to NSArray/NSMutableArray need not to be released.

IBOutlet,IBAction为你开启了访问Interface Build中对象的大门

  1. IBOutlet and IBAction open the door to access the objects in Interface build.

UIApplicationDelegate负责应用程序的生命周期,而UIViewController负责View的生命周期

  1. UIApplicationDelegate is responsible for the application life cycle,but UIViewController for the UIView.

为了程序的健壮性,请尽量实现Delegate的生命周期函数

  1. if you want to develop a robust application,implement the life cycle methods as more as possbile.

you触摸的不是UIEvent,而是NSSet的UIView

  1. what you touch on screen is not UIEvent but UIView

UITextField不响应键盘:

  1. 方法1: TextField的的Touch Cancel响应中,添加[textFied resignFirstResponder];
  2. 方法: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  3. [textFied resignFirstResponder]; }

更改响应键盘return按钮:

  1. TextField.returnKeyType=UIReturnKeyDone;
  2. select:
  3. UIReturnKeyDefault,
  4. UIReturnKeyGo,
  5. UIReturnKeyGoogle,
  6. UIReturnKeyJoin,
  7. UIReturnKeyNext,
  8. UIReturnKeyRoute,
  9. UIReturnKeySearch,
  10. UIReturnKeySend,
  11. UIReturnKeyYahoo,
  12. UIReturnKeyDone,
  13. UIReturnKeyEmergencyCall,

尺寸问题:

  1. iPhone应用程序图标大小:57*57;
  2. iPhone全屏UIView大小:320*460 添加UITabBar后大小:320*411
  3. UITabelViewCell默认大小: 320*44

绘制控件方法

  1. //--alloc
  2. -(UITextField *)GetDefaultTextField:(CGRect)frame{
  3. UITextField *textField=[[UITextField alloc] initWithFrame:frame];
  4. textField.borderStyle=UITextBorderStyleRoundedRect;
  5. textField.font=[UIFont fontWithName:@"Arial"size:12.0];
  6. textField.textAlignment=UITextAlignmentCenter;
  7. textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
  8. textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  9. textField.returnKeyType=UIReturnKeyDone;
  10. textField.delegate=self;
  11. returntextField;
  12. }
  13. //--alloc
  14. -(UILabel *)GetDefaultLabel:(CGRect)frame{
  15. UILabel *label = [[UILabel alloc] initWithFrame: frame];
  16. label.textAlignment=UITextAlignmentCenter;
  17. label.textColor=[UIColor blackColor];
  18. label.backgroundColor=[UIColor clearColor];
  19. label.font=[UIFont boldSystemFontOfSize:12.0];
  20. returnlabel;
  21. }
  22. //--alloc
  23. -(UIButton *)GetDefaultButton:(CGRect)frame{
  24. UIButton *button=[[UIButton alloc] initWithFrame:frame];
  25. [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  26. [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
  27. [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  28. [button.titleLabel setFont:[UIFont boldSystemFontOfSize:14.0]];
  29. [button.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
  30. [button addTarget:self action:@selector(btnTradeTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
  31. [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
  32. [button setBackgroundImage:[UIImage imageNamed:@"png1.png"] forState:UIControlStateNormal];
  33. [button setBackgroundColor:[UIColor lightGrayColor]];
  34. button.tag=kButtonTag;
  35. returnbutton;}

多使用宏定义常量。tag,frame大小,一些判断标志位。

 
1
#define kIndexValueTag 1

苹果屏幕截图快捷键

一般在Mac上用Command-Shif-3/4来截图。注:Command=苹果键 其实还有几个辅助键,来起到不同的截图功能……

  1. 1)Command-Shift-3(适用于OS9,10.1X和10.2)
  2. 将整个屏幕拍下并保存到桌面。
  3. 2)Command-Shift-4(适用于OS9,10.1X和10.2)
  4. 将屏幕的一部分拍下并保存到桌面。当按下着几个键后,光标会变为一个十字,可以拖拉来选取拍报区域。
  5. 3)Command-Shift-Control-3(适用于OS9和10.2)
  6. 将整个屏幕拍下并保存到剪贴板,可以Command+V直接粘贴到如Photoshop等软件中编辑。
  7. 4)Command-Shift-Control-4(适用于OS9和10.2)
  8. 将屏幕的一部分拍下并保存到剪贴板。
  9. 5)Command-Shift-4再按空格键(适用于10.2)
  10. 光标会变成一个照相机,点击可拍下当前窗口或菜单或Dock以及图标等,只要将照相机移动到不用区域(有效区域会显示为浅蓝色)点击。
  11. 6)Command-Shift-Control-4再按空格键(适用于10.2)
  12. 将选取的窗口或其他区域的快照保存到剪贴板。
  13. 7)Command-Shift-Capslock-4(适用于OS9)
  14. 将当前的窗口拍下并保存到桌面。
  15. 8)Command-Shift-Capslock-Control-4(适用于OS9)
  16. 将当前的窗口拍下并保存到剪贴板

IOS代码收集的更多相关文章

  1. 漫谈iOS Crash收集框架

    漫谈iOS Crash收集框架   Crash日志收集 为了能够第一时间发现程序问题,应用程序需要实现自己的崩溃日志收集服务,成熟的开源项目很多,如 KSCrash,plcrashreporter,C ...

  2. IOS试题收集1

    IOS试题收集1 1.Objective C中有多继承吗?没有的话用什么代替? Protocol 2.Objective C中有私有方法吗?私有变量呢? OC类里面只有静态方法和实例方法这两种,@pr ...

  3. 李洪强iOS开发之iOS社区收集

    李洪强iOS开发之iOS社区收集 项目 简述 github 全球最大的代码仓库,无论是iOS开发还是Android开发没有人不知道这个网站,它也是一个社区,你可以去follow(关注)某些人或公司. ...

  4. 李洪强iOS开发之iOS工具收集

    李洪强iOS开发之iOS工具收集 项目 简述 日期 我是怎么慢慢变懒的 : Jenkins + 蒲公英 使用Jenkins + 蒲公英使得项目打包给测试人员自动化,大大节省了劳动力 2015.04.1 ...

  5. 李洪强IOS开发之iOS好项目收集

    李洪强IOS开发之iOS好项目收集 在这里收集一些最近出现的比较实用好玩的框架或者项目,会不断更新 项目 简述 日期 SCTableViewCell 类似与QQ侧滑删除Cell的Demo 201501 ...

  6. iOS代码签名理解

    前言 做了几年iOS app coder了,对于证书的生成.使用流程烂熟于心,然而对于这套机制的原理却一直不甚理解.近来由于工作需要仔细研究了一下,特将自己的学习经验记录于此,以供大家学习指正. 问题 ...

  7. iOS代码加密常用加密方式

    iOS代码加密常用加密方式 iOS代码加密常用加密方式,常见的iOS代码加密常用加密方式算法包括MD5加密.AES加密.BASE64加密,三大算法iOS代码加密是如何进行加密的,且看下文 MD5 iO ...

  8. 如何把iOS代码编译为Android应用

    新闻 <iPhone 6/6 Plus中国销量曝光:单月销量650万>:据iSuppli Corp.中国研究总监王阳爆料,iPhone 6和iPhone 6 Plus在国内受欢迎的情况大大 ...

  9. Xcode之外的文档浏览工具--Dash (在iOS代码库中浏览本帖)

    链接地址:http://www.cocoachina.com/bbs/read.php?tid=273479 Xcode之外的文档浏览工具--Dash    (在iOS代码库中浏览本帖)       ...

随机推荐

  1. 使用JQuery.Validate插件来校验页面表单有效性

    使用JQuery.Validate插件来校验页面表单有效性​1. [代码] 常见的注册表单元素 <form action="#" method="post" ...

  2. GDUT 积木积水 2*n 时间复杂度

    题意 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元,于是他把这个三维的现实问 ...

  3. 汇编环境的搭建(windows 10 + debug)

    1. debug.exe 安装 win10 版本过高,不再提供 debug.exe,甚至从别处获取的 debug.exe 的也无法运行. 汇编语言学习所需的各种执行文件(debug.exe.link. ...

  4. SpringMVC之使用Validator接口进行验证

    对于任何一个应用而言在客户端做的数据有效性验证都不是安全有效的,这时候就要求我们在开发的时候在服务端也对数据的有效性进行验证.SpringMVC自身对数据在服务端的校验有一个比较好的支持,它能将我们提 ...

  5. Eclipse全项目搜索指定文件&字串

    在eclipse中如果希望在大量的项目中寻找指定的文件可不是一件轻松的事,还好eclipse提供了强大的搜索功能. 我们可以通过通配符或正则表达式来设定查寻条件,下面是操作示例: ctrl+h 打开搜 ...

  6. page-break-before和page-break-after

    page-break-before和page-break-after CSS属性并不会修改网页在屏幕上的显示,这两个属性是用来控制文件的打印方式. 每个打印属性都可以设定4种设定值:auto.alwa ...

  7. C#面向对象之数据库(理论、插入、修改、删除、查询)

    1.数据库的作用:不仅仅是存储,更重要的是将数据进行存储以后怎么样才能方便快捷的查询修改 2.数据库的特点:海量存储.查找速度快.并发性问题控制.安全性.数据完整性(保存在数据库中的数据是正确的.真是 ...

  8. Entity Framework 实体间的外键关系

    EF 默认是开户级联删除的,这此规则将会删除非空外键和多对多的关系,如果 在数据库上下文中的实体模型类 存在着 级联引用和多重删除路径,那么EF就抛出 级联引用和多重删除路径的异常. Introduc ...

  9. fzu2280 Magic(暴力+哈希预处理)

    传送门 题意 q次操作,每次两种操作: 1 x y:将wx变成y 2 x:查询满足一下两个条件的字符串(①以字符串x为后缀②字符串值\(\le wx\)) 分析 对n个字符串预处理,设f[i][j]为 ...

  10. hdoj5402 【模拟/构造】

    题意: 给你一个矩阵,每个值都是非负,然后让你从左上角走到右下角,每个点只能走一次,求到终点的最大值,还要输出一条路径 思路: 一开始拿到还以为搜索之类的,但是发现神特么暴力+麻烦(因为路径这个东西. ...