intrinsicContentSize//固有的,内容,尺寸
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake((K_Width-160)/2, 100, 160, 60)];
label.backgroundColor=[UIColor redColor];
label.textColor=[UIColor blackColor];
label.textAlignment=NSTextAlignmentCenter;
label.numberOfLines=0;
label.text=@"你好啊,提莫队长,真是个小朋友";
[self.view addSubview:label];
NSLog(@"--->%.2f",label.intrinsicContentSize.width);
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake((K_Width-160)/2, 200, 160, 60)];
textField.text=@"伤心伤心伤心伤心1";
textField.backgroundColor=[UIColor blueColor];
textField.textAlignment=NSTextAlignmentCenter;
textField.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:textField];
NSLog(@"输入框的内容的宽度-->%.2f",textField.intrinsicContentSize.width);
}