Frage

I'm following a tutorial where I create a CGSize like this:

 CGSize size = [self.label.text sizeWithFont:(UIFont) forWidth:(CGFloat) lineBreakMode:(NSLineBreakMode)];

First of all what does this mean, what does it do? And I saw it has deprecated in iOS 7 and is replaced with drawInRect:WithAttribute. Does this do the same thing and how is it used?

Thanks in advance!

War es hilfreich?

Lösung

If you alt-click on the method in Xcode it will tell you what it does.

This specific method returns a CGSize (struct with two fields - width and height) that is getting calculated by NSString (text in your label) for specific font and limited length.

For example you want to know how big will your label be in order to position other elements on screen. This method helps you since it returns the size that said label will occupy.

The method to replace this is boundingRectWithSize:options:attributes:context: that does the same thing

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top