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. Scrapy爬虫报错:ModuleNotFoundError: No module named 'win32api'

    运行 scrapy crawl douban_spider 出现报错: 解决办法:安装pywin32,下载适配安装的Python版本(64位,Python3.6) 下载地址: https://sour ...

  2. 【hdu 2222】Keywords Search

    [题目链接] 点击打开链接 [算法] 此题是AC自动机模板题 AC自动机是很神奇的算法,简单点来说,就是在一棵字典树上进行KMP,它的应用范围很广,非常实用 这篇博客写得很好,推荐阅读 : http: ...

  3. fastText(二):微博短文本下fastText的应用(一)

    众所周知,微博中的内容以短文本居多,文本内容随意性极强,这给建模增加了很大的难度.针对这一问题,这里分享一下fastText在微博短文本的应用. 任务目标简单介绍一下整个任务的目标:给微博内容打上标签 ...

  4. Vue scrollBehavior 滚动行为

    使用前端路由,当切换到新路由时,想要页面滚到顶部,或者是保持原先的滚动位置,就像重新加载页面那样. vue-router 能做到,而且更好,它让你可以自定义路由切换时页面如何滚动. 注意: 这个功能只 ...

  5. ORACLE PL/SQL 实例精解之第三章 PL/SQL中的SQL

    3.1 在PL/SQL中使用DML 在PL/SQL语块中,两种变量赋值a. := 初始化.b. select into语法,PL/SQL语块的声明部分被声明的变量,后期可以使用选择语句进行赋值. 3. ...

  6. C++笔试题(三)

    普天是南京一家通信公司,全称为:南京普天通信股份有限公司,公司网址为:http://www.postel.com.cn 网上流传一套普天C++笔试题,我将我做的答案公布与此,仅供参考. 1.实现双向链 ...

  7. 关于<?php exit;?>"的绕过问题

    在Moctf中看到一道题目: <?php show_source(__FILE__); $c="<?php exit;?>"; @$c.=$_POST['c']; ...

  8. STL排序和检索

    //参考书是刘汝佳的那本算法书P108 //sort的用法也就是本来是从小到大排序,如果想要从大到小,中间写一个比较函数就可以了: //以下两个检索的东西 //lower_bound找到一个值的最小插 ...

  9. dijkstra算法的应用(poj2387)+堆优化【还没学C艹很尴尬,不理解的先不写了,未完,待续...】

    一题非常简单的最短路题目,但是我就是很撒比的错在了,1.初始化:2.判断重边 堆优化,使用优先队列的堆优化:复杂度:O(ElogE); #include <stdio.h> #includ ...

  10. hdoj1272【并查集】

    因为是第二遍,所以题目也没怎么看,然后一开始的思路就是如果每次输入两个点的时候判断是不是同一个集合,如果同一个就是No,然后就wa了,想想也是,然后瞄了一下题解,还要判连通-真是蠢死了-多个集合都想不 ...