【问题标题】:How to find all characters in the first line of the uilabel如何查找uilabel第一行中的所有字符
【发布时间】:2014-02-24 11:05:39
【问题描述】:

我想计算行数并从给定文本中动态查找 UILabel 第一行中的所有字符。我正在为 uilabel 使用自动换行。是否可以。请帮助和指导我。

【问题讨论】:

标签: ios iphone objective-c ios7 uilabel


【解决方案1】:

这样试试

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];

【讨论】:

  • 如果有任何问题请告诉我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-19
相关资源
最近更新 更多