priore

UILabel and text size for iOS 7

Dec 12th, 2013
665
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
  2.     #define MyLabelAlignmentCenter NSTextAlignmentCenter
  3. #else
  4.     #define MyLabelAlignmentCenter UITextAlignmentCenter
  5. #endif
  6.  
  7. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
  8.     #define My_TEXTSIZE(text, font) [text length] > 0 ? [text \
  9.         sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero;
  10. #else
  11.     #define My_TEXTSIZE(text, font) [text length] > 0 ? [text sizeWithFont:font] : CGSizeZero;
  12. #endif
  13.  
  14. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
  15.     #define My_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
  16.         boundingRectWithSize:maxSize options:(NSStringDrawingUsesLineFragmentOrigin) \
  17.         attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero;
  18. #else
  19.     #define My_MULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
  20.         sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero;
  21. #endif
RAW Paste Data