【发布时间】:2014-02-24 11:05:39
【问题描述】:
我想计算行数并从给定文本中动态查找 UILabel 第一行中的所有字符。我正在为 uilabel 使用自动换行。是否可以。请帮助和指导我。
【问题讨论】:
标签: ios iphone objective-c ios7 uilabel
我想计算行数并从给定文本中动态查找 UILabel 第一行中的所有字符。我正在为 uilabel 使用自动换行。是否可以。请帮助和指导我。
【问题讨论】:
标签: ios iphone objective-c ios7 uilabel
这样试试
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];
【讨论】: