How to tell when a UILabel will be truncated an/or its line break position will change

后端 未结 5 1345
栀梦
栀梦 2021-01-13 01:38

I have a multi-line UILabel (numberOfLines = 0). It\'s width can change at runtime, and sometimes this leads to truncation and/or re-wrapping. Some

5条回答
  •  梦谈多话
    2021-01-13 02:18

    Use this method to find lable truncated in iOS 7.

    - (BOOL)isTruncated:(UILabel *)label{
            CGSize sizeOfText = [label.text boundingRectWithSize: CGSizeMake(label.bounds.size.width, CGFLOAT_MAX)
                                                         options: (NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                                      attributes: [NSDictionary dictionaryWithObject:label.font forKey:NSFontAttributeName] context: nil].size;
    
            if (self.frame.size.height < ceilf(sizeOfText.height)) {
                return YES;
            }
            return NO;
        }
    

提交回复
热议问题