How to get a UIView that displays text that will behave like a UILabel when changing borders?

I have a UIView in which I need to draw text in drawRect:

- (void)drawRect:(CGRect)rect {
    ...
    [@"some text" drawAtPoint:somePoint withFont:someFont];
    ...
}

Since the text requires special formatting, I cannot just use UILabel.

It looks great until I rotate the device. Then the size of my custom UIView is resized (in the parent view method layoutSubviews), and the text is stretched in one direction and compressed in the other.

When I replace my view with UILabel, the text always looks great even when changing the borders of the view.

How can I get an idea of ​​the same behavior as UILabel?

Some things that I learned but have not yet been successful:

  • Set the required display level of DisplayOnBoundsChange to YES.
  • contentStretch CGRectZero.
  • setNeedsDisplay layoutSubviews.

, . - ?

: , contentMode UIViewContentModeRedraw, . . /, , / . UILabel.

+3
4

contentMode UIViewContentModeRedraw.

+5

, :

self.contentMode = UIViewContentModeRedraw;
self.contentStretch = CGRectMake(1, 1, 0.5, 0.5);

, . . , UILabel , - . , , .

+2

, FontLabel. (code.google.com)

, UILabel, ;)

//EDIT: ok ok, , , UILabel "to get all the UILabel goodness" ^^

+1

UIWebView

It sounds a little redundant, but it seems that it is recommended that you use rich text that is more complex than UILabel can handle.

+1
source

Source: https://habr.com/ru/post/1769882/


All Articles