您的位置:首页 > 其它

获取字符串内容的宽度,label.text的宽度,以及textField.text的宽度问题

2016-04-19 11:42 447 查看
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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: