Aaron Brager
Aaron Brager

Reputation: 66242

What's the width of this UIView with a custom drawRect method?

I have a custom UILabel subclass. The only method I'm overriding is the drawRect method, outlined here.

When I pass the UILabel's bounds.size or frame.size or layer.bounds.size to - (CGSize)sizeThatFits:(CGSize)size I am returned the value that the UILabel would be if not for the custom drawing. That is, the CGSize returned has too small a width since I'm increasing the spacing between letters.

What is the proper way to get the correct width, accounting for my custom drawing?

Upvotes: 1

Views: 107

Answers (1)

rob mayoff
rob mayoff

Reputation: 385610

The proper way is to override sizeThatFits: yourself to compute the proper size. UIKit can't do it for you.

Upvotes: 2

Related Questions