Krelborn / KILabel

A simple to use drop in replacement for UILabel for iOS 7 and above that highlights links such as URLs, twitter style usernames and hashtags and makes them touchable.
MIT License
470 stars 132 forks source link

Auto layout #3

Closed wnr closed 10 years ago

wnr commented 10 years ago

Hello, would this work with auto layouting? I noticed that all UILabel replacement projects that I found all use the initWithFrame approach, which doesn't really go along so well with auto layout when you want the label to fill a certain (at compile-time unknown) area.

Or am I missing something?

Thanks

Krelborn commented 10 years ago

Yes it will. KILabel overrides initWithCoder which is the constructor used when loading from a nib file. There's no need to use initWithFrame at all, just use a UILabel on your storyboard and then set its class to KILabel in the inspector. You'll get all the benefits of auto-layout etc. You just have to set a few of the more advanced properties in code yourself once your nib is loaded.

Hope that helps.

wnr commented 10 years ago

Thank you for your reply :)

The thing is that I build the interface from code and I'm not using any xib or storyboard files. Usually I would create my UILabel's with something like ÙILabel *label = [[UILabel alloc] init]; to later set the text of the label and then call the [label setTranslatesAutoresizingMaskIntoConstraints:NO]; to later completely let auto layout do the heavy work.

How would I use KILabel with the same approach as described? Should I call initWithCoder or perhaps initWithFrame:CGRectZero?

Thank you

EDIT: I should've tried it before asking, but I guess I have tried so many non-working UILabels that I got tired of it. You can ignore this comment since your KILabel seems to work great, just as expected!

Great job! :)

Krelborn commented 10 years ago

Good to know. I thought it would work, thanks for the update.