iphone开发笔记
1 1、退回输入键盘 2 3 - (BOOL) textFieldShouldReturn:(id)textField{ 4 5 [textField resignFirstResponder]; 6 7 } 8 9 2、CGRect 10 11 CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形 12 13 NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串; 14 15 CGRectFromString(aString) 由字符串恢复出矩形; 16 17 CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大 18 19 CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠 20 21 CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量 22 23 24 3、CGPoint & CGSize 25 26 CGPoint aPoint = CGPointMake(x, y); 27 28 CGSize aSize = CGSizeMake(width, height); 29 30 4、设置透明度 31 32 [myView setAlpha:value]; (0.0 < value < 1.0) 33 34 5、设置背景色 35 36 [myView setBackgroundColor:[UIColor redColor]]; 37 38 (blackColor;darkGrayColor;lightGrayColor; 39 40 whiteColor;grayColor; redColor; greenColor; 41 42 blueColor; cyanColor;yellowColor; 43 44 magentaColor;orangeColor;purpleColor; 45 46 brownColor; clearColor; ) 47 48 6、自定义颜色 49 50 UIColor *newColor = [[UIColor alloc] 51 52 initWithRed:(float) green:(float) blue:(float) alpha:(float)]; 53 54 0.0~1.0 55 56 7、隐藏状态栏 57 58 [[UIApplication shareApplication] setStatusBarHidden: YES animated:NO] 59 60 8、横屏 61 62 [[UIApplication shareApplication] 63 64 setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]. 65 66 9、屏幕变动检测 67 68 orientation == UIInterfaceOrientationLandscapeLeft 69 70 10、全屏 71 72 window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds]; 73 74 11、自动适应父视图大小: 75 76 aView.autoresizingSubviews = YES; 77 78 aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight); 79 80 12、 定义按钮 81 82 UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 83 84 [scaleUpButton setTitle:@"放 大" forState:UIControlStateNormal]; 85 86 scaleUpButton.frame = CGRectMake(40, 420, 100, 40); 87 88 [scaleUpButton addTarget:self action:@selector(scaleUp) 89 90 forControlEvents:UIControlEventTouchUpInside]; 91 92 13、设置视图背景图片 93 94 UIImageView *aView; 95 96 [aView setImage:[UIImage imageNamed:@”name.png”]]; 97 98 view1.backgroundColor = [UIColor colorWithPatternImage: 99 100 [UIImage imageNamed:@"image1.png"]]; 101 102 14、从Plist里读内容 103 104 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"book" ofType:@"plist"]; 105 106 NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; 107 108 NSString *book = [dictionary objectForKey:bookTitle]; 109 110 [textView setText:book]; 111 112 113 114 (void) initialize { 115 116 NSUserDefaults = [NSUserDefaults standardUserDefaults]; 117 118 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES" forKey:@"DeleteBackup"]; 119 120 [defaults registerDefaults:appDefaults]; 121 122 } 123 124 125 126 To get a value of a default, use the valueForKey: method: 127 128 [[theDefaultsController values] valueForKey:@"userName"]; 129 130 To set a value for a default, use setValue:forKey: 131 132 [[theDefaultsController values] setValue:newUserName forKey:@"userName"]; 133 134 135 136 [[NSUserDefaults standardUserDefaults] setValue:aVale forKey:aKey]; 137 138 [[NSUserDefaults standardUserDefaults] valueForKey:aKey]; 139 140 15、获取Documents目录 141 142 NSArray *paths = NSSearchPathForDictionariesInDomains(NSDocumentDirectory, 143 144 NSUserDomainMask, YES); 145 146 NSString *documentsDirectory = [paths objectAtIndex:0]; 147 148 NSString *filename = [documentsDirectory 149 150 stringByAppendingPathComponent:@"theFile.txt"]; 151 152 153 154 获取tmp目录 155 156 NSString *tempPath = NSTemporaryDirectory(); 157 158 NSString *tempFile = [tempPath stringByAppendingPathComponent:@"tempFile.txt"]; 159 160 161 162 [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"someKey"]; 163 164 [[NSUserDefaults standardUserDefaults] objectForKey:aKey]; 165 166 16、 167 -(BOOL) isKindOfClass:class // 对象是不是class或其子类成员 168 169 -(BOOL) isMemberOfClass:class // 对象是不是class的成员 170 171 -(BOOL) respondsToSelector:selector // 对象是否能够相应selector所指定的方法 172 173 +(BOOL) instancesRespondToSelector:selector // 指定对象实力是否能响应selector 174 175 +(BOOL) isSubclassOfClass:class // 对象是否指定类的子类 176 177 -(id) performSwlector:selector // 应用selector指定的方法 178 179 -(id) perforumSelector:selector widthObject:object // 应用selector指定方法传参object