2015-01-23

ILabel – the self sized UILabel for iOS

Views: 14738 | Add Comments

One of the fundamental basis of CocoaUI is Auto Flow(Auto Layout), so self-sizing is supported by all CocoaUI controls including ILabel, IButton, IInput, IImage, and so on. In this article, I would like to introduce ILabel, the self sized UILabel for iOS.

When using ILabel to display single-line text or multi-line text, you don’t have worry about the frame size of the text label, ILabel will calculate the width and height of the text, and resize the frame size automatically.

This is the bad codes when using UIKit’s UILabel:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
label.text = @"Text here...";
[label sizeToFit];

The sizeToFit sometimes don’t work as you would expect.

This is the good codes when using CocoaUI’s ILabel:

ILabel *label = [ILabel labelWithText:@"Text here..."];

I am not missing any codes there, it is a single line of code! Whenever you change the text of the label, it will auto resize its’ frame size.

Posted by ideawu at 2015-01-23 11:00:55 Tags: ,

Leave a Comment