您的位置:首页 > 移动开发 > IOS开发

小知识,随手一记

2014-12-30 13:33 169 查看
1.进入相机或者相册页面,想要使里面的使用,拍照变成中文:Localized resouces can be mixed = yes;   在info.plist里添加。

2.sendSubviewToBack ,bringSubviewToFront,exchangeSubviewAtIndex: withSubviewAtIndex:,调整view的层次

3.我也不知道这个对不对,反正我是这种情况:在tablebiew的协议里,用ifififif就行,用if else 就不行,如果遇到这种情况的可以试一下,毕竟我也不是什么大牛,只是自己摸索积累下来的。

4.UILable的自适应:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMakeZero;  
//设置自动行数与字符换行 ,0是无上限
[label setNumberOfLines:0];  
label.lineBreakMode = UILineBreakModeWordWrap;  
//换行方式
// 测试字串  
 NSString *s = @"钻石之所以珍贵,是因为它的极坚硬度以及开采难度。但是世界上有10种比钻石更加稀有,更加珍贵的宝石散落在世界的某个角落。甚至有些宝石的名字都很少被人提起。它们不仅数量稀少,开采成本及难度超高,甚至至今都难以切出一颗完整形状的宝石。但是其独特的色彩及光泽依然让世界上的宝石爱好者对其痴迷不已。";  
UIFont *font = [UIFont fontWithName:@"Arial" size:12];  
//设置一个行高上限  
CGSize size = CGSizeMake(320,2000);  
//计算实际frame大小,并将label的frame变成实际大小  
 CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];  
[label setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];

5.很多地方我们都使用16进制颜色,但iPhone使用的是UIColor对象,不直接支持16进制颜色,为此,需要我们手动将16进制颜色转换为UIColor
- (UIColor *)stringToColor:(NSString*)color
{
unsigned int red,green,blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[color substringWithRange:range]]scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[color substringWithRange:range]]scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[color substringWithRange:range]]scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green / 255.0f) blue:(float)(blue / 255.0f)alpha:1.0f];
}

6.CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 5.0'的情况:

Project -----Build Setting-----Code Signing



7.%%打印出%,别说这个水,有时候真的会忘。

8.非arc加入arc,-fno-objc-arc arc加入非arc,-fobjc-arc

9.exit(x)强制退出程序,0表示正常退出,除0以外的所有值都便是不正常退出。

10.block代替代理:

typedef void (^block)(int);

.h文件里:

@propety (monatomic,copy) block bl;

.m文件里:

if(self.deleg response)换成 if(self.bl);

然后在需要指明代理的地方实例化这个block就能起到和代理一样的作用了。

11.iOS shadowColor //加阴影   

_imageView.layer.shadowColor = [UIColor yellowColor].CGColor;//shadowColor阴影颜色

_imageView.layer.shadowOffset = CGSizeMake(4,4);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用      _imageView.layer.shadowOpacity = 0.8;//阴影透明度,默认0

_imageView.layer.shadowRadius = 4;//阴影半径,默认3

12.KVO机制 addObserver: forKeyPath: options:context: 对象的属性对应的值必须是对象,不能是基本的数据类型。当对象的属性变化时,观察者就会接受到通知,贯彻者需要重写方法:observerVaalueForKeyPath: ofObject:change
context: 以影响属性的变化.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 开发笔记