priore

UILabel text size fit macro

Jan 16th, 2014
711
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // UILabel text size fit macro
  2. //
  3. // use :
  4. //
  5. // UILabel *label = ....
  6. // TEXT_FIT(label, @"your text here");
  7. //
  8. #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  9. #define TEXT_FIT_IOS6(t,txt)  (CGRect){t.frame.origin, t.frame.size.width, [txt sizeWithFont:t.font constrainedToSize:t.frame.size lineBreakMode:t.lineBreakMode].height}
  10. #define TEXT_FIT_IOS7(t,txt) (CGRect){t.frame.origin, t.frame.size.width, [txt boundingRectWithSize:t.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:t.font} context:nil].size.height}
  11. #define TEXT_FIT(t,txt) {t.text = txt;t.numberOfLines = 0;t.frame = SYSTEM_VERSION_LESS_THAN(@"7.0")?TEXT_FIT_IOS6(t,txt):TEXT_FIT_IOS7(t,txt);}
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×