在iOS开发中经常需要使用的或不常用的知识点的总结,几年的收藏和积累(踩过的坑)。
一、 iPhone Size
手机型号 | 屏幕尺寸 |
---|---|
iPhone 4 4s | 320 * 480 |
iPhone 5 5s | 320 * 568 |
iPhone 6 6s | 375 * 667 |
iphone 6 plus 6s plus | 414 * 736 |
二、 给navigation Bar 设置 title 颜色
1 2 3 |
UIColor *whiteColor = [UIColor whiteColor]; NSDictionary *dic = [NSDictionary dictionaryWithObject:whiteColor forKey:NSForegroundColorAttributeName]; [self.navigationController.navigationBar setTitleTextAttributes:dic]; |
三、 如何把一个CGPoint存入数组里
1 2 3 4 5 6 |
CGPoint itemSprite1position = CGPointMake(100, 200); NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:NSStringFromCGPoint(itemSprite1position),nil]; // 从数组中取值的过程是这样的: CGPoint point = CGPointFromString([array objectAtIndex:0]); NSLog(@"point is %@.", NSStringFromCGPoint(point)); |
谢谢@bigParis的建议,可以用NSValue进行基础数据的保存,用这个方法更加清晰明确。
1 2 3 4 5 6 7 8 |
CGPoint itemSprite1position = CGPointMake(100, 200); NSValue *originValue = [NSValue valueWithCGPoint:itemSprite1position]; NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:originValue, nil]; // 从数组中取值的过程是这样的: NSValue *currentValue = [array objectAtIndex:0]; CGPoint point = [currentValue CGPointValue]; NSLog(@"point is %@.", NSStringFromCGPoint(point)); |
现在Xcode7后OC支持泛型了,可以用NSMutableArray *array
来保存。
四、 UIColor 获取 RGB 值
1 2 3 4 5 6 |
UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0]; const CGFloat *components = CGColorGetComponents(color.CGColor); NSLog(@"Red: %f", components[0]); NSLog(@"Green: %f", components[1]); NSLog(@"Blue: %f", components[2]); NSLog(@"Alpha: %f", components[3]); |
五、 修改textField的placeholder的字体颜色、大小
1 2 3 |
self.textField.placeholder = @"username is in here!"; [self.textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [self.textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; |
六、两点之间的距离
1 |
static __inline__ CGFloat CGPointDistanceBetweenTwoPoints(CGPoint point1, CGPoint point2) { CGFloat dx = point2.x - point1.x; CGFloat dy = point2.y - point1.y; return sqrt(dx*dx + dy*dy);} |
七、IOS开发-关闭/收起键盘方法总结
>二、 给navigation Bar 设置 title 颜色
1 2 3 |
UIColor *whiteColor = [UIColor whiteColor]; NSDictionary *dic = [NSDictionary dictionaryWithObject:whiteColor forKey:NSForegroundColorAttributeName]; [self.navigationController.navigationBar setTitleTextAttributes:dic]; |
三、 如何把一个CGPoint存入数组里
1 2 3 4 5 6 |
CGPoint itemSprite1position = CGPointMake(100, 200); NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:NSStringFromCGPoint(itemSprite1position),nil]; // 从数组中取值的过程是这样的: CGPoint point = CGPointFromString([array objectAtIndex:0]); NSLog(@"point is %@.", NSStringFromCGPoint(point)); |
谢谢@bigParis的建议,可以用NSValue进行基础数据的保存,用这个方法更加清晰明确。
1 2 3 4 5 6 7 8 |
CGPoint itemSprite1position = CGPointMake(100, 200); NSValue *originValue = [NSValue valueWithCGPoint:itemSprite1position]; NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:originValue, nil]; // 从数组中取值的过程是这样的: NSValue *currentValue = [array objectAtIndex:0]; CGPoint point = [currentValue CGPointValue]; NSLog(@"point is %@.", NSStringFromCGPoint(point)); |
现在Xcode7后OC支持泛型了,可以用NSMutableArray *array
来保存。
四、 UIColor 获取 RGB 值
1 2 3 4 5 6 |
UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0]; const CGFloat *components = CGColorGetComponents(color.CGColor); NSLog(@"Red: %f", components[0]); NSLog(@"Green: %f", components[1]); NSLog(@"Blue: %f", components[2]); NSLog(@"Alpha: %f", components[3]); |
五、 修改textField的placeholder的字体颜色、大小
1 2 3 |
self.textField.placeholder = @"username is in here!"; [self.textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [self.textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; |
六、两点之间的距离
1 |
static __inline__ CGFloat CGPointDistanceBetweenTwoPoints(CGPoint point1, CGPoint point2) { CGFloat dx = point2.x - point1.x; CGFloat dy = point2.y - point1.y; return sqrt(dx*dx + dy*dy);} |
七、IOS开发-关闭/收起键盘方法总结
d-line" id="crayon-5812a866ade75436252508-4">CGPoint point = CGPointFromString([array objectAtIndex:0]);NSLog(@"point is %@.", NSStringFromCGPoint(point));