//7.0以前使用
//判断当前系统的软件版本
float f = [UIDevice currentDevice].systemVersion.floatValue;
if (f>=7.0) {
NSLog(@"使用7.0方法");
}else{
NSLog(@"使用7.0之前的方法");
}
NSString *str =@"dafsdsafsdaj jkalsdg saldfjl skdaf jsladk flsdkaj flksadjflksa jglksadjglashdkfsdajlkfjsad lgsdjalkgadsljf lasd;";
//计算完整显示上面的文字需要的size
/*
参数一:字体 字号
参数二:最大的尺寸范围
*/
//计算字体时 以17号字体为基准计算 计算出来的结果最大宽度320 最大的高度2000
CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(320, 2000)];
NSLog(@"%f,%f",size.width,size.height);
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, size.width, size.height)];
label.backgroundColor =[UIColor greenColor];
label.text =str;
label.numberOfLines = 0;
[self.window addSubview:label];
[label release];