2014-02-24 20 views
0

我想計算行數並從給定文本中動態查找UILabel第一行中的所有字符。我爲uilabel使用wordwrapping。可能嗎。請幫助和指導我。如何在uilabel的第一行中找到所有字符

+1

這可能幫助你:http://stackoverflow.com/questions/4421267/how-to-get-text-from-nth-line-of-uilabel –

回答

0

嘗試這樣

UILabel *thisyourlabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
     thisyourlabel.numberOfLines = 0; 
     thisyourlabel.lineBreakMode = UILineBreakModeWordWrap; 
     thisyourlabel.text = @"I want to calculate number of lines and find all characters in the first line of the UILabel dynamically from given text. I'm using wordwrapping for uilabel. Is it possible. Please help and guide me"; 

     CGRect frame = thisyourlabel.frame; 
     frame.size.width = 200.0f; 
     frame.size = [thisyourlabel sizeThatFits:frame.size]; 
     thisyourlabel.frame = frame; 

     CGFloat lineHeight = thisyourlabel.font.leading; 
     NSUInteger linesInLabel = floor(frame.size.height/lineHeight); 
     NSLog(@"Number of lines in label: %i", linesInLabel); 

     [self.view addSubview: thisyourlabel]; 
+0

讓我知道是否有問題 – Sport

相關問題