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. IntelliJ IDEA 注册码 有效期截止于2018/10/14

    来源: http://idea.lanyus.com/ IntelliJ IDEA 注册码: EB101IWSWD-eyJsaWNlbnNlSWQiOiJFQjEwMUlXU1dEIiwibGljZW ...

  2. linux初级学习笔记五:bash特性详解!(视频序号:03_2,3)

    本节学习的命令:history,alias,ualias,\CMD 本节学习的技能:   bash的特性 光标跳转 查看命令历史 命令历史的使用技巧 给命令起别名 命令替换 文件名通配符 shell: ...

  3. poj 2531 Network Saboteur 解题报告

    题目链接:http://poj.org/problem?id=2531 题目意思:将 n 个点分成两个部分A和B(也就是两个子集啦), 使得子集和最大(一定很难理解吧,呵呵).举个例子吧,对于样例,最 ...

  4. Linux下使用pip安装keras

    Keras是一个底层使用Theano或TensorFlow的深度学习框架,它的设计参考了Torch,用Python语言编写,也很方便使用Python调用,是一个高度模块化的神经网络库,支持使用GPU和 ...

  5. Educational Codeforces Round 23

    A题 分析:注意两个点之间的倍数差,若为偶数则为YES,否则为NO #include "iostream" #include "cstdio" #include ...

  6. JQ的双向数据绑定

    把渲染页面封装在function里面 在修改后直接调用,但是如果有alert();一定要注意function的摆放位置,正常应该是在alert前面,应为如果在后面会影响重新渲染的效果

  7. margin和padidng的使用

    何时应当使用margin:需要在border外侧添加空白时.空白处不需要背景(色)时.上下相连的两个盒子之间的空白,需要相互抵消时.如15px + 20px的margin,将得到20px的空白. 何时 ...

  8. MySQL中的RAND()函数使用详解

    转自:https://www.jb51.net/article/66697.htm MySQL RAND()函数调用可以在0和1之间产生一个随机数: ? 1 2 3 4 5 6 7 mysql> ...

  9. Codechef SEPT17

    Codechef SEPT17 比赛链接:https://www.codechef.com/SEPT17 CHEFSUM code给定数组 a[1..n] ,求最小的下标 i ,使得 prefixsu ...

  10. easyui 动态添加标签页,总结

    步骤 1:创建 Tabs <div style="margin-bottom:10px"> <a href="#" class="e ...