#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UILabel *labelOne;
@property(nonatomic,strong)UILabel *labelTwo;
@property(nonatomic,copy)NSString *str;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *[email protected]"搜房网是全球最大的房地产家居网络平台,页面浏览量和访问量在同类网站中处于绝对领先地位。拥有9000名员工,网络业务覆盖300多个城市,在中国100多个城市拥有分公司和办公室。2010年9月搜房网(股票代码SFUN)在美国纽约证券交易所成功上市。搜房网是全球最大的房地产家居网络平台,页面浏览量和访问量在同类网站中处于绝对领先地位。拥有9000名员工,网络业务覆盖300多个城市,在中国100多个城市拥有分公司和办公室。2010年9月搜房网(股票代码SFUN)在美国纽约证券交易所成功上市。";
self.str=strOne;
self.labelOne=[[UILabel alloc]init];
self.labelOne.numberOfLines=0;
self.labelOne.font=[UIFont systemFontOfSize:14];
self.labelOne.textAlignment=NSTextAlignmentCenter;
self.labelOne.text=strOne;
self.labelTwo=[[UILabel alloc]init];
self.labelTwo.numberOfLines=0;
self.labelTwo.font=[UIFont systemFontOfSize:20];
self.labelTwo.textAlignment=NSTextAlignmentCenter;
self.labelTwo.text=strOne;
[self.view addSubview:self.labelOne];
[self.view addSubview:self.labelTwo];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
CGRect labelOneFrame=[self.str boundingRectWithSize:CGSizeMake(200, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];[super viewWillAppear:animated];
CGPoint PointOne=CGPointMake(100, 50);
CGRect labelframe;
labelframe.origin=PointOne;
labelframe.size=labelOneFrame.size;
self.labelOne.frame=labelframe;
CGRect labelTwoFrame=[self.str boundingRectWithSize:CGSizeMake(200, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
CGPoint PointTwo=CGPointMake(self.labelOne.frame.origin.x, CGRectGetMaxY(self.labelOne.frame));
labelframe.origin=PointTwo;
labelframe.size=labelTwoFrame.size;
self.labelTwo.frame=labelframe;
}
@end
其实用自动布局就不用这么麻烦了