float curHeight =20;
//字体字典 修改字典
//ios7.0
NSDictionary *dic;
if (SYSTEMVERSION_7) {
UIFont *font =[UIFont systemFontOfSize:17];
dic =[NSDictionary dictionaryWithObjectsAndKeys:font, nil];
}
for (int i =0; i<arr.count; i++) {
CGSize size = CGSizeMake(0, 0);
if (SYSTEMVERSION_7) {
size =[arr[i] boundingRectWithSize:CGSizeMake(200, 2000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil].size;
}else{
size = [arr[i] sizeWithFont:[UIFont boldSystemFontOfSize:17] constrainedToSize:CGSizeMake(200, 2000)];
}
UILabel * label = nil;
if (i%2 == 0) {
label = [[UILabel alloc] initWithFrame:CGRectMake(5, curHeight, size.width, size.height)];
}else{
label = [[UILabel alloc] initWithFrame:CGRectMake(320-size.width, curHeight, size.width, size.height)];
}
label.text = arr[i];
label.numberOfLines = 0;
[self.window addSubview:label];
[label release];
curHeight += size.height;
}
pch文件中
#define SYSTEMVERSION_7 ([[UIDevice currentDevice] systrmVersion].floatValue>7.0);