UILineBreakMode Vs NSLineBreakMode

mootymoots picture mootymoots · Oct 3, 2012 · Viewed 11.2k times · Source

I see some UIStringDrawing methods have been updated to use NSLineBreakMode instead of UILineBreakMode in iOS 6.0:

E.g.

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode

How can I check for this to ensure my iOS 5 users and below continue to use UILineBreakMode?

Answer

brynbodayle picture brynbodayle · Oct 3, 2012

No checking is necessary. These are just enums and they map to the same values

You can see there is no real difference here:

UILineBreakMode vs NSLineBreakMode

  enum {
   NSLineBreakByWordWrapping = 0,
   NSLineBreakByCharWrapping,
   NSLineBreakByClipping,
   NSLineBreakByTruncatingHead,
   NSLineBreakByTruncatingTail,
   NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMode



typedef enum {
   UILineBreakModeWordWrap = 0,
   UILineBreakModeCharacterWrap,
   UILineBreakModeClip,
   UILineBreakModeHeadTruncation,
   UILineBreakModeTailTruncation,
   UILineBreakModeMiddleTruncation,
} UILineBreakMode;