- 浏览: 26005 次
- 性别:
- 来自: 沈阳
-
文章分类
最新评论
转载一片ipad开发文章,以备后用。
感谢作者分享
iPad开发乱乱记
浏览: 714 评论: 0 发表评论 作者: 聖騎天下
iPad开发相关的技巧、知识等等的笔记,比较乱,姑且称作乱乱记吧:P
退回输入键盘:
查看源代码打印帮助
1 - (BOOL) textFieldShouldReturn:(id)textField{
2 [textField resignFirstResponder];
3 }
CGRect
查看源代码打印帮助
1 CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形
2 NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串;
3 CGRectFromString(aString) 由字符串恢复出矩形;
4 CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大
5 CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠
6 CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量
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
5 UISlider *slider = (UISlider *) sender;
6 NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
7 label.text = newText;
活动表单 <UIActionSheetDelegate>
查看源代码打印帮助
01 - (IBActive) someButtonPressed:(id) sender
02 {
03 UIActionSheet *actionSheet = [[UIActionSheet alloc]
04 initWithTitle:@”Are you sure?”
05 delegate:self
06 cancelButtonTitle:@”No way!”
07 destructiveButtonTitle:@”Yes, I’m Sure!”
08 otherButtonTitles:nil];
09 [actionSheet showInView:self.view];
10 [actionSheet release];
11 }
警告视图 <UIAlertViewDelegate>
查看源代码打印帮助
01 - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
02 {
03 if(buttonIndex != [actionSheet cancelButtonIndex])
04 {
05 NSString *message = [[NSString alloc] initWithFormat:@”You can
06 breathe easy, everything went OK.”];
07 UIAlertView *alert = [[UIAlertView alloc]
08 initWithTitle:@”Something was done”
09 message:message
10 delegate:self
11 cancelButtonTitle:@”OK”
12 otherButtonTitles:nil];
13 [alert show];
14 [alert release];
15 [message release];
16 }
17 }
动画效果
查看源代码打印帮助
01 -(void)doChange:(id)sender
02 {
03 if(view2 == nil)
04 {
05 [self loadSec];
06 }
07 [UIView beginAnimations:nil context:NULL];
08 [UIView setAnimationDuration:1];
09 [UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];
10
11 if([view1 superview]!= nil)
12 {
13 [view1 removeFromSuperview];
14 [self.view addSubview:view2];
15
16 }else {
17
18 [view2 removeFromSuperview];
19 [self.view addSubview:view1];
20 }
21 [UIView commitAnimations];
22 }
Table View <UITableViewDateSource>
查看源代码打印帮助
01 #pragma mark -
02 #pragma mark Table View Data Source Methods
03 //指定分区中的行数,默认为1
04 - (NSInteger)tableView:(UITableView *)tableView
05 numberOfRowsInSection:(NSInteger)section
06 {
07 return [self.listData count];
08 }
09
10 //设置每一行cell显示的内容
11 - (UITableViewCell *)tableView:(UITableView *)tableView
12 cellForRowAtIndexPath:(NSIndexPath *)indexPath
13 {
14 static NSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
15 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
16 if (cell == nil) {
17 cell = [[[UITableViewCell alloc]
18 initWithStyle:UITableViewCellStyleSubtitle
19 reuseIdentifier:SimpleTableIndentifier]
20 autorelease];
21 }
22 UIImage *image = [UIImage imageNamed:@"13.gif"];
23 cell.imageView.image = image;
24
25 NSUInteger row = [indexPath row];
26 cell.textLabel.text = [listData objectAtIndex:row];
27 cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
28
29 if(row < 5)
30 cell.detailTextLabel.text = @"Best friends";
31 else
32 cell.detailTextLabel.text = @"friends";
33 return cell;
34 }
图像:如果设置图像,则它显示在文本的左侧
文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签)
详细文本标签:这是单元的辅助文本,通常用作解释性说明或标签
查看源代码打印帮助
01 UITableViewCellStyleSubtitle
02 UITableViewCellStyleDefault
03 UITableViewCellStyleValue1
04 UITableViewCellStyleValue2
05
06 <UITableViewDelegate>
07 #pragma mark -
08 #pragma mark Table View Delegate Methods
09 //把每一行缩进级别设置为其行号
10 - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
11 {
12 NSUInteger row = [indexPath row];
13 return row;
14 }
15 //获取传递过来的indexPath值
16 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
17 {
18 NSUInteger row = [indexPath row];
19 if (row == 0)
20 return nil;
21 return indexPath;
22 }
23
24 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
25 {
26 NSUInteger row = [indexPath row];
27 NSString *rowValue = [listData objectAtIndex:row];
28 NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];
29 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected"
30 message:message
31 delegate:nil
32 cancelButtonTitle:@"Yes, I did!"
33 otherButtonTitles:nil];
34 [alert show];
35 [alert release];
36 [message release];
37 [tableView deselectRowAtIndexPath:indexPath animated:YES];
38 }
39
40 //设置行的高度
41 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
42 {
43 return 40;
44 }
随机数的使用
查看源代码打印帮助
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文件并存储
-
查看源代码打印帮助
01 NSString *errorDesc; //用来存放错误信息
02 NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件
03 NSDictionary *innerDict;
04 NSString *name;
05 Player *player;
06 NSInteger saveIndex;
07 for(int i = 0; i < [playerArray count]; i++) {
08 player = nil;
09 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方法就可以写成文件。下面是代码:
查看源代码打印帮助
01 /*得到移动设备上的文件存放位置*/
02 NSString *documentsPath = [self getDocumentsDirectory];
03 NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
04
05 /*存文件*/
06 if (plistData) {
07 [plistData writeToFile:savePath atomically:YES];
08 }
09 else {
10 NSLog(errorDesc);
11 [errorDesc release];
12 }
13
14 - (NSString *)getDocumentsDirectory {
15 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
16 return [paths objectAtIndex:0];
17 }
读取plist文件并转化为NSDictionary
查看源代码打印帮助
1 NSString *documentsPath = [self getDocumentsDirectory];
2 NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
3 NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];
读取一般性文档文件
查看源代码打印帮助
01 NSString *tmp;
02 NSArray *lines; /*将文件转化为一行一行的*/
03 lines = [[NSString stringWithContentsOfFile:@"testFileReadLines.txt"]
04 componentsSeparatedByString:@”\n”];
05 NSEnumerator *nse = [lines objectEnumerator];
06 // 读取<>里的内容
07 while(tmp = [nse nextObject]) {
08 NSString *stringBetweenBrackets = nil;
09 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中使用就可以了。
如果无法保证子类行为的一致性,那么就用委托
If the subClass cann’t keep with superClass,use delegate rather than inheritance.
屏幕上看到的,都是UIVew
Everything you see on Screen is UIView.
如果对性能要求高,慎用Interface Build
if application’s performance is important,be discreet for the interface build.
copy是创建,retain是引用
the copy operation is create a new one,but the retain operation is just a reference.
alloc需要release,convenient不需要release
alloc method need corresponding release method,but convenient method not.
加载到NSArray/NSMutableArray里的对象,不需要负责release
The objects added to NSArray/NSMutableArray need not to be released.
IBOutlet,IBAction为你开启了访问Interface Build中对象的大门
IBOutlet and IBAction open the door to access the objects in Interface build.
UIApplicationDelegate负责应用程序的生命周期,而UIViewController负责View的生命周期
UIApplicationDelegate is responsible for the application life cycle,but UIViewController for the UIView.
为了程序的健壮性,请尽量实现Delegate的生命周期函数
if you want to develop a robust application,implement the life cycle methods as more as possbile.
you触摸的不是UIEvent,而是NSSet的UIView
what you touch on screen is not UIEvent but UIView
UITextField不响应键盘:
查看源代码打印帮助
1 方法1: TextField的的Touch Cancel响应中,添加[textFied resignFirstResponder];
2
3 方法: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
4
5 [textFied resignFirstResponder]; }
更改响应键盘return按钮:
查看源代码打印帮助
01 TextField.returnKeyType=UIReturnKeyDone;
02 select:
03 UIReturnKeyDefault,
04 UIReturnKeyGo,
05 UIReturnKeyGoogle,
06 UIReturnKeyJoin,
07 UIReturnKeyNext,
08 UIReturnKeyRoute,
09 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
绘制控件方法
查看源代码打印帮助
01 //--alloc
02 -(UITextField *)GetDefaultTextField:(CGRect)frame{
03
04 UITextField *textField=[[UITextField alloc] initWithFrame:frame];
05 textField.borderStyle=UITextBorderStyleRoundedRect;
06 textField.font=[UIFont fontWithName:@"Arial" size:12.0];
07 textField.textAlignment=UITextAlignmentCenter;
08 textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
09 textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
10 textField.returnKeyType=UIReturnKeyDone;
11 textField.delegate=self;
12 return textField;
13
14 }
15 //--alloc
16 -(UILabel *)GetDefaultLabel:(CGRect)frame{
17
18 UILabel *label = [[UILabel alloc] initWithFrame: frame];
19 label.textAlignment=UITextAlignmentCenter;
20 label.textColor=[UIColor blackColor];
21 label.backgroundColor=[UIColor clearColor];
22 label.font=[UIFont boldSystemFontOfSize:12.0];
23 return label;
24 }
25 //--alloc
26 -(UIButton *)GetDefaultButton:(CGRect)frame{
27
28 UIButton *button=[[UIButton alloc] initWithFrame:frame];
29 [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
30 [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
31 [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
32 [button.titleLabel setFont:[UIFont boldSystemFontOfSize:14.0]];
33 [button.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
34 [button addTarget:self action:@selector(btnTradeTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
35 [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
36
37 [button setBackgroundImage:[UIImage imageNamed:@"png1.png"] forState:UIControlStateNormal];
38 [button setBackgroundColor:[UIColor lightGrayColor]];
39 button.tag=kButtonTag;
40
41 return button;}
多使用宏定义常量。tag,frame大小,一些判断标志位。
查看源代码打印帮助
1 #define kIndexValueTag 1
苹果屏幕截图快捷键
一般在Mac上用Command-Shif-3/4来截图。注:Command=苹果键 其实还有几个辅助键,来起到不同的截图功能……
查看源代码打印帮助01 1)Command-Shift-3(适用于OS9,10.1X和10.2)
02 将整个屏幕拍下并保存到桌面。
03 2)Command-Shift-4(适用于OS9,10.1X和10.2)
04 将屏幕的一部分拍下并保存到桌面。当按下着几个键后,光标会变为一个十字,可以拖拉来选取拍报区域。
05 3)Command-Shift-Control-3(适用于OS9和10.2)
06 将整个屏幕拍下并保存到剪贴板,可以Command+V直接粘贴到如Photoshop等软件中编辑。
07 4)Command-Shift-Control-4(适用于OS9和10.2)
08 将屏幕的一部分拍下并保存到剪贴板。
09 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
Command-Shift-Capslock-Control-4(适用于OS9)
16 将当前的窗口拍下并保存到剪贴板。
iPad开发乱乱记
浏览: 714 评论: 0 发表评论 作者: 聖騎天下
iPad开发相关的技巧、知识等等的笔记,比较乱,姑且称作乱乱记吧:P
退回输入键盘:
查看源代码打印帮助
1 - (BOOL) textFieldShouldReturn:(id)textField{
2 [textField resignFirstResponder];
3 }
CGRect
查看源代码打印帮助
1 CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形
2 NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串;
3 CGRectFromString(aString) 由字符串恢复出矩形;
4 CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大
5 CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠
6 CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量
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
5 UISlider *slider = (UISlider *) sender;
6 NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
7 label.text = newText;
活动表单 <UIActionSheetDelegate>
查看源代码打印帮助
01 - (IBActive) someButtonPressed:(id) sender
02 {
03 UIActionSheet *actionSheet = [[UIActionSheet alloc]
04 initWithTitle:@”Are you sure?”
05 delegate:self
06 cancelButtonTitle:@”No way!”
07 destructiveButtonTitle:@”Yes, I’m Sure!”
08 otherButtonTitles:nil];
09 [actionSheet showInView:self.view];
10 [actionSheet release];
11 }
警告视图 <UIAlertViewDelegate>
查看源代码打印帮助
01 - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
02 {
03 if(buttonIndex != [actionSheet cancelButtonIndex])
04 {
05 NSString *message = [[NSString alloc] initWithFormat:@”You can
06 breathe easy, everything went OK.”];
07 UIAlertView *alert = [[UIAlertView alloc]
08 initWithTitle:@”Something was done”
09 message:message
10 delegate:self
11 cancelButtonTitle:@”OK”
12 otherButtonTitles:nil];
13 [alert show];
14 [alert release];
15 [message release];
16 }
17 }
动画效果
查看源代码打印帮助
01 -(void)doChange:(id)sender
02 {
03 if(view2 == nil)
04 {
05 [self loadSec];
06 }
07 [UIView beginAnimations:nil context:NULL];
08 [UIView setAnimationDuration:1];
09 [UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];
10
11 if([view1 superview]!= nil)
12 {
13 [view1 removeFromSuperview];
14 [self.view addSubview:view2];
15
16 }else {
17
18 [view2 removeFromSuperview];
19 [self.view addSubview:view1];
20 }
21 [UIView commitAnimations];
22 }
Table View <UITableViewDateSource>
查看源代码打印帮助
01 #pragma mark -
02 #pragma mark Table View Data Source Methods
03 //指定分区中的行数,默认为1
04 - (NSInteger)tableView:(UITableView *)tableView
05 numberOfRowsInSection:(NSInteger)section
06 {
07 return [self.listData count];
08 }
09
10 //设置每一行cell显示的内容
11 - (UITableViewCell *)tableView:(UITableView *)tableView
12 cellForRowAtIndexPath:(NSIndexPath *)indexPath
13 {
14 static NSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
15 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
16 if (cell == nil) {
17 cell = [[[UITableViewCell alloc]
18 initWithStyle:UITableViewCellStyleSubtitle
19 reuseIdentifier:SimpleTableIndentifier]
20 autorelease];
21 }
22 UIImage *image = [UIImage imageNamed:@"13.gif"];
23 cell.imageView.image = image;
24
25 NSUInteger row = [indexPath row];
26 cell.textLabel.text = [listData objectAtIndex:row];
27 cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
28
29 if(row < 5)
30 cell.detailTextLabel.text = @"Best friends";
31 else
32 cell.detailTextLabel.text = @"friends";
33 return cell;
34 }
图像:如果设置图像,则它显示在文本的左侧
文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签)
详细文本标签:这是单元的辅助文本,通常用作解释性说明或标签
查看源代码打印帮助
01 UITableViewCellStyleSubtitle
02 UITableViewCellStyleDefault
03 UITableViewCellStyleValue1
04 UITableViewCellStyleValue2
05
06 <UITableViewDelegate>
07 #pragma mark -
08 #pragma mark Table View Delegate Methods
09 //把每一行缩进级别设置为其行号
10 - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
11 {
12 NSUInteger row = [indexPath row];
13 return row;
14 }
15 //获取传递过来的indexPath值
16 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
17 {
18 NSUInteger row = [indexPath row];
19 if (row == 0)
20 return nil;
21 return indexPath;
22 }
23
24 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
25 {
26 NSUInteger row = [indexPath row];
27 NSString *rowValue = [listData objectAtIndex:row];
28 NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];
29 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected"
30 message:message
31 delegate:nil
32 cancelButtonTitle:@"Yes, I did!"
33 otherButtonTitles:nil];
34 [alert show];
35 [alert release];
36 [message release];
37 [tableView deselectRowAtIndexPath:indexPath animated:YES];
38 }
39
40 //设置行的高度
41 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
42 {
43 return 40;
44 }
随机数的使用
查看源代码打印帮助
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文件并存储
-
查看源代码打印帮助
01 NSString *errorDesc; //用来存放错误信息
02 NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件
03 NSDictionary *innerDict;
04 NSString *name;
05 Player *player;
06 NSInteger saveIndex;
07 for(int i = 0; i < [playerArray count]; i++) {
08 player = nil;
09 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方法就可以写成文件。下面是代码:
查看源代码打印帮助
01 /*得到移动设备上的文件存放位置*/
02 NSString *documentsPath = [self getDocumentsDirectory];
03 NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
04
05 /*存文件*/
06 if (plistData) {
07 [plistData writeToFile:savePath atomically:YES];
08 }
09 else {
10 NSLog(errorDesc);
11 [errorDesc release];
12 }
13
14 - (NSString *)getDocumentsDirectory {
15 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
16 return [paths objectAtIndex:0];
17 }
读取plist文件并转化为NSDictionary
查看源代码打印帮助
1 NSString *documentsPath = [self getDocumentsDirectory];
2 NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
3 NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];
读取一般性文档文件
查看源代码打印帮助
01 NSString *tmp;
02 NSArray *lines; /*将文件转化为一行一行的*/
03 lines = [[NSString stringWithContentsOfFile:@"testFileReadLines.txt"]
04 componentsSeparatedByString:@”\n”];
05 NSEnumerator *nse = [lines objectEnumerator];
06 // 读取<>里的内容
07 while(tmp = [nse nextObject]) {
08 NSString *stringBetweenBrackets = nil;
09 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中使用就可以了。
如果无法保证子类行为的一致性,那么就用委托
If the subClass cann’t keep with superClass,use delegate rather than inheritance.
屏幕上看到的,都是UIVew
Everything you see on Screen is UIView.
如果对性能要求高,慎用Interface Build
if application’s performance is important,be discreet for the interface build.
copy是创建,retain是引用
the copy operation is create a new one,but the retain operation is just a reference.
alloc需要release,convenient不需要release
alloc method need corresponding release method,but convenient method not.
加载到NSArray/NSMutableArray里的对象,不需要负责release
The objects added to NSArray/NSMutableArray need not to be released.
IBOutlet,IBAction为你开启了访问Interface Build中对象的大门
IBOutlet and IBAction open the door to access the objects in Interface build.
UIApplicationDelegate负责应用程序的生命周期,而UIViewController负责View的生命周期
UIApplicationDelegate is responsible for the application life cycle,but UIViewController for the UIView.
为了程序的健壮性,请尽量实现Delegate的生命周期函数
if you want to develop a robust application,implement the life cycle methods as more as possbile.
you触摸的不是UIEvent,而是NSSet的UIView
what you touch on screen is not UIEvent but UIView
UITextField不响应键盘:
查看源代码打印帮助
1 方法1: TextField的的Touch Cancel响应中,添加[textFied resignFirstResponder];
2
3 方法: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
4
5 [textFied resignFirstResponder]; }
更改响应键盘return按钮:
查看源代码打印帮助
01 TextField.returnKeyType=UIReturnKeyDone;
02 select:
03 UIReturnKeyDefault,
04 UIReturnKeyGo,
05 UIReturnKeyGoogle,
06 UIReturnKeyJoin,
07 UIReturnKeyNext,
08 UIReturnKeyRoute,
09 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
绘制控件方法
查看源代码打印帮助
01 //--alloc
02 -(UITextField *)GetDefaultTextField:(CGRect)frame{
03
04 UITextField *textField=[[UITextField alloc] initWithFrame:frame];
05 textField.borderStyle=UITextBorderStyleRoundedRect;
06 textField.font=[UIFont fontWithName:@"Arial" size:12.0];
07 textField.textAlignment=UITextAlignmentCenter;
08 textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
09 textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
10 textField.returnKeyType=UIReturnKeyDone;
11 textField.delegate=self;
12 return textField;
13
14 }
15 //--alloc
16 -(UILabel *)GetDefaultLabel:(CGRect)frame{
17
18 UILabel *label = [[UILabel alloc] initWithFrame: frame];
19 label.textAlignment=UITextAlignmentCenter;
20 label.textColor=[UIColor blackColor];
21 label.backgroundColor=[UIColor clearColor];
22 label.font=[UIFont boldSystemFontOfSize:12.0];
23 return label;
24 }
25 //--alloc
26 -(UIButton *)GetDefaultButton:(CGRect)frame{
27
28 UIButton *button=[[UIButton alloc] initWithFrame:frame];
29 [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
30 [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
31 [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
32 [button.titleLabel setFont:[UIFont boldSystemFontOfSize:14.0]];
33 [button.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];
34 [button addTarget:self action:@selector(btnTradeTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
35 [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
36
37 [button setBackgroundImage:[UIImage imageNamed:@"png1.png"] forState:UIControlStateNormal];
38 [button setBackgroundColor:[UIColor lightGrayColor]];
39 button.tag=kButtonTag;
40
41 return button;}
多使用宏定义常量。tag,frame大小,一些判断标志位。
查看源代码打印帮助
1 #define kIndexValueTag 1
苹果屏幕截图快捷键
一般在Mac上用Command-Shif-3/4来截图。注:Command=苹果键 其实还有几个辅助键,来起到不同的截图功能……
查看源代码打印帮助01 1)Command-Shift-3(适用于OS9,10.1X和10.2)
02 将整个屏幕拍下并保存到桌面。
03 2)Command-Shift-4(适用于OS9,10.1X和10.2)
04 将屏幕的一部分拍下并保存到桌面。当按下着几个键后,光标会变为一个十字,可以拖拉来选取拍报区域。
05 3)Command-Shift-Control-3(适用于OS9和10.2)
06 将整个屏幕拍下并保存到剪贴板,可以Command+V直接粘贴到如Photoshop等软件中编辑。
07 4)Command-Shift-Control-4(适用于OS9和10.2)
08 将屏幕的一部分拍下并保存到剪贴板。
09 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
![](/images/smiles/icon_cool.gif)
16 将当前的窗口拍下并保存到剪贴板。
相关推荐
JESD79-2F DDR2 JESD79-3F DDR3 JESD79-4D DDR4 JESD79-5C DDR5 JESD209-2F LPDDR2 JESD209-3C LPDDR3 JESD209-4E LPDDR4 JESD209-4-1A LPDDR4X JESD209-5C LPDDR5(X)
COMSOL二维光子晶体角态研究:单胞与超胞能带计算及边界态与角态特性分析,COMSOL二维光子晶体角态研究:单胞与超胞能带计算及边界态与角态特性分析,comsol二维光子晶体角态。 单胞能带,超胞能带,边界态以及角态计算。 ,comsol;二维光子晶体;角态;单胞能带;超胞能带;边界态计算,基于Comsol的二维光子晶体角态及能带边界计算研究
六自由度机械臂抓取动作仿真与代码解析:抓取动画、关节参数变化及轨迹图解详解,六自由度机械臂抓取动作仿真指南:掌握两套代码实现动画与轨迹图模拟学习攻略,六自由度机械臂抓取动作仿真-8 两套关于抓取动作的代码,包括抓取动画、关节角、角速度、角加速度的变化仿真、以及抓取轨迹图 简单易懂好上手~ ,六自由度机械臂;抓取动作仿真;抓取动画;关节角变化;角速度角加速度;抓取轨迹图;两套代码;简单易懂好上手,六自由度机械臂抓取动作仿真演示:代码与轨迹图解
ITC网络广播工具软件
Multisim四位密码锁电路仿真设计:设定、开锁与声光报警功能演示资料包,Multisim四位密码锁电路仿真设计:设定、输入、开锁与报警功能详解,附源文件、原理说明书与演示视频,multisim四位密码锁电路仿真设计 功能: 1.通过拨码开关1进行初始密码设定。 2.通过拨码开关2输入密码,实现开锁判断。 3.如果密码正确,LED绿灯亮,表示开锁。 4.如果密码不正确,LED红灯亮,蜂鸣器鸣叫,声光报警。 资料包含:仿真源文件+原理说明书+演示视频 ,四位密码锁电路、Multisim仿真设计、初始密码设定;拨码开关输入;开锁判断;LED灯显示;声光报警;仿真源文件;原理说明书;演示视频,Multisim四位密码锁电路仿真设计:初始密码设置与智能解锁功能的声光报警展示
俗话说,摸鱼摸的好,上班没烦恼,毕竟谁能拒绝带薪拉屎呢(手动狗头) 这是一个云开发职场打工人专属上班摸鱼划水微信小程序源码,没有后台 直接导入微信开发者工具即可运行,UI简约大气漂亮,只需登录微信公众平台配置完合法域名即可轻松上线。 用户进入摸鱼小程序,可以自由设置薪资,上班时间、下班时间、发薪日、 月工作天数以提醒自己摸鱼,全民打酱油,让自己成为摸鱼冠军,《商鞅摸鱼哲学》 摸鱼不是自我放纵,而是个人实力的积蓄,我们的小目标是晚睡晚起 小程序中的今日待办会提醒用户带薪拉屎和闲逛,下方展示的是距离休息日的天数,距离下一次发工资的天数和节日的天数。
【毕业设计】基于Java的开发的一个集合校园二手交易、拼车、失物招领等功能的app_pgj
个人记录:PICkit3离线烧录流程 使用软件:MPLAB X IDE v5.30 记录时间:20250215
基于Matlab代码的电力系统状态估计与实验仿真研究:扩展卡尔曼滤波和无迹卡尔曼滤波在电力系统动态状态估计中的应用及效果分析,Matlab仿真实验研究:基于扩展卡尔曼滤波器与无迹卡尔曼滤波器对电力系统状态估计的影响及验证,状态估计 电力系统状态估计 Matlab代码 实验仿真研究 电力系统由于测量值和传输误差,还有测量噪声的影响,会对状态估计产生影响。 因此,需要对嘈杂的测量进行滤波,以获得准确的电力系统运行动态。 本文使用扩展卡尔曼滤波器(EKF)和无迹卡尔曼滤波器(UKF)来估计电力系统的动态状态。 扩展卡尔曼滤波EKF、无迹卡尔曼滤波UKF 利用扩展的无迹卡尔曼滤波器估计了动力系统的动态状态。 对WECC 3机9总线系统和新英格兰10机39总线系统进行了案例研究。 结果表明EKF和UKF都能准确地估计电力系统的动态状态。 ,核心关键词:状态估计; 电力系统状态估计; Matlab代码; 实验仿真; 测量值误差; 测量噪声; 扩展卡尔曼滤波器(EKF); 无迹卡尔曼滤波器(UKF); 动力系统; 动态状态估计; WECC 3机9总线系统; 新英格兰10机39总线系统。,Matlab
springboot在线考试--
台达DVP EH3与MS300 PLC&变频器通讯程序的全面解决方案,台达DVP EH3与MS300通讯程序:稳定可靠的频率控制与启停管理系统,台达DVP EH3与台达MS300通讯程序(TDEH-9) 可直接用于实际的程序,程序带注释,并附送触摸屏程序,有接线方式和设置,通讯地址说明等。 程序采用轮询,可靠稳定 器件:台达DVP EH3系列PLC,台达MS300系列变频器,昆仑通态7022Ni 功能:实现频率设定,启停控制,实际频率读取,加减速时间设定。 资料:带注释程序,触摸屏程序,接线和设置说明,后续有技术咨询。 ,核心关键词:台达DVP EH3; 台达MS300; 通讯程序(TDEH-9); 轮询; 稳定; 频率设定; 启停控制; 实际频率读取; 加减速时间设定; 触摸屏程序; 接线方式; 设置说明; 技术咨询。,台达PLC与变频器通讯程序(带注释、触摸屏控制)
项目资源包含:可运行源码+sql文件 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。项目具有较高的学习借鉴价值,也可拿来修改、二次开发。 个人账户管理:支持用户注册、登录与个人信息编辑;提供密码找回及账号安全保护措施。 声纹采集:利用麦克风设备录制用户的声纹样本;支持多种录音格式和质量调整,确保采集到清晰、准确的声纹数据。 声纹模板库管理:建立和维护一个安全的声纹模板库;支持声纹模板的添加、删除、更新和查询操作。 声纹比对与识别:运用深度学习算法对输入的声纹数据进行特征提取和匹配;实现快速、准确的声纹身份验证。 多场景应用支持:适用于多种场景,如门禁系统、移动支付、远程登录等;可根据实际需求定制开发相应的应用场景。 实时监控与报警:实时监控系统运行状态,包括声纹识别成功率、处理速度等指标;当出现异常情况时,及时发出报警信息。 数据分析与报告生成:收集并分析声纹识别过程中的数据,如识别准确率、处理时间等;根据用户需求输出包含详细图表说明的专业级文档供下载打印保存。 社区互动交流:设立论坛版块鼓励用户分享心得体会讨论热点话题;定期邀请行业专家举办线上讲座传授实用技巧知识。 音乐筛选与推荐:集成音乐平台API,根据用户的浏览习惯和情绪状态推荐背景音乐,增强用户体验。 数据可视化:提供交互式的数据可视化面板,使非技术用户也能轻松理解复杂的数据集,从而做出更明智的决策。
三相与多相开绕组永磁同步电机仿真模型的先进控制策略探讨与实现,三相与多相开绕组永磁同步电机的Simulink仿真模型与先进控制策略研究,开绕组电机,开绕组永磁同步电机仿真模型、simulink仿真 共直流母线、独立直流母线,两相容错,三相容错控制,零序电流抑制,控制策略很多 三相开绕组永磁同步电机,六相开绕组永磁同步电机 五相开绕组永磁同步电机,五相开绕组电机 ,开绕组电机; 永磁同步电机仿真模型; simulink仿真; 共直流母线; 独立直流母线; 两相容错; 三相容错控制; 零序电流抑制; 控制策略; 六相开绕组永磁同步电机; 五相开绕组永磁同步电机,开绕组电机仿真研究:共直流母线与独立直流母线的容错控制策略
【毕业设计】基于Java的开发的网上汽车租赁管理系统_pgj
csv 模块是 Python 的标准库,无需额外安装。 运行结果如下图: ['姓名', '年龄', '城市'] ['张三', '25', '北京'] ['李四', '30', '上海'] ['王五', '22', '广州']
【毕业设计】基于Java+Springboot+Vue的宠物领养系统_pgj
让前端开发者学习“机器学习”!
【毕业设计】基于Java的实现的以宠物为主体的论坛式的APP
大模型应用工具实战2-有好玩的数字人
【毕业设计】基于ssm的选课管理系统