최대 행 수가 4 개인 UITextView
입니다. 각 줄 뒤에 UILabels
을 붙이고 싶지만 각 줄마다 많은 텍스트를 포함하고 싶습니다.UITextview의 여러 줄 너비를 계산하는 방법은 무엇입니까?
각 코더의 선의 너비를 계산하는 방법에 대한 아이디어가 있으십니까?
최대 행 수가 4 개인 UITextView
입니다. 각 줄 뒤에 UILabels
을 붙이고 싶지만 각 줄마다 많은 텍스트를 포함하고 싶습니다.UITextview의 여러 줄 너비를 계산하는 방법은 무엇입니까?
각 코더의 선의 너비를 계산하는 방법에 대한 아이디어가 있으십니까?
이 하나
UIFont *font=[UIFont systemFontOfSize:17.0f];
UILabel *yourLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 80)];
yourLabel.numberOfLines=4;
[email protected]"Hello\nHulo\nMe\nyou";
CGSize labelSize = [yourLabel.text sizeWithFont:font
constrainedToSize:yourLabel.frame.size
lineBreakMode:NSLineBreakByTruncatingTail];
CGFloat singleLineHeight = labelSize.height/yourLabel.numberOfLines;
[self.view addSubview:yourLabel];
는 하나의 줄 높이가 약 21
NSLog(@"single line height is %f",singleLineHeight);
텍스트보기 위해이 규정을 따르
UITextView *yourView=[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
yourView.font=[UIFont systemFontOfSize:14.0f];
yourView.text = @"Hello \nmy\n Friend\n Hru? ";
CGSize textViewSize = [yourView.text sizeWithFont:yourView.font
constrainedToSize:CGSizeMake(yourView.frame.size.width, FLT_MAX)
lineBreakMode:NSLineBreakByTruncatingTail];
[yourView setFrame:CGRectMake(0, 0, textViewSize.width, textViewSize.height)];
[self.view addSubview:yourView];
NSLog(@"single line height is %f",yourView.frame.size.height);
이것은 높이를 얻는데 완벽하게 작동합니다. 모든 라인의 너비를 얻으려면 어떻게해야합니까? – liquidpenguins
너는 너가 단 하나 선의 높이 그리고 너비를 얻고 싶다는 것을 의미한다 – Warewolf
몇 분을 기다려 – Warewolf
구글'는 NSString UIKit extensions'됩니다 시도 , + , 바다 '크기'를위한 rch. –