2013-06-03 2 views

답변

3

이 하나

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); 
+0

이것은 높이를 얻는데 완벽하게 작동합니다. 모든 라인의 너비를 얻으려면 어떻게해야합니까? – liquidpenguins

+0

너는 너가 단 하나 선의 높이 그리고 너비를 얻고 싶다는 것을 의미한다 – Warewolf

+0

몇 분을 기다려 – Warewolf

관련 문제