Lines missing from tall UILabel when embedding NSTextAttachment

前端 未结 4 1951
陌清茗
陌清茗 2020-12-16 12:12

I can create a multi-line NSAttributedString by using escaped new-line characters (@\"\\n\"). With iOS 7, I can now embed a UIImage in

4条回答
  •  独厮守ぢ
    2020-12-16 12:33

    I have found another workaround for this bug, which is sufficiently different from my previous answer that I'm providing it as another answer: let the label set its own height.

    In this code, I'm removing the height constraint from a label with a fixed width constraint, and replacing it with a greater-than height constraint (and I'm sure there are other ways to achieve the same outcome):

    [self.lab removeConstraint:self.labelHeight];
    [self.lab addConstraint:
     [NSLayoutConstraint constraintWithItem:self.lab 
     attribute:NSLayoutAttributeHeight 
     relatedBy:NSLayoutRelationGreaterThanOrEqual 
     toItem:nil attribute:0 multiplier:1 constant:20]];
    

    That label displays correctly every attributed string I throw at it! Of course, you lose the automatic vertical centering of the string, but that's the whole source of the bug, so losing it is not so terrible.

提交回复
热议问题