I need my app to support iOS 5+. Since prior iOS 6 the enum lineBreakMode
for line break mode in UILabel
is of type UILineBreakMode
, and it is of type NSLineBreakMode
for iOS 6+, what should be the best (or more correct) way to check the iOS version currently running to determine the type to be used? Is it correct to directly do something like [[UIDevice currentDevice] systemVersion]
, or is there a better way?
Thanks!
You do not need to check the iOS version at runtime, the enum values are the same, the compiled code will not be changed when moving from UILineBreakMode
to NSLineBreakMode
enum {
NSLineBreakByWordWrapping = 0,
NSLineBreakByCharWrapping,
NSLineBreakByClipping,
NSLineBreakByTruncatingHead,
NSLineBreakByTruncatingTail,
NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMode
typedef enum {
UILineBreakModeWordWrap = 0,
UILineBreakModeCharacterWrap,
UILineBreakModeClip,
UILineBreakModeHeadTruncation,
UILineBreakModeTailTruncation,
UILineBreakModeMiddleTruncation,
} UILineBreakMode;
In case you want to check for the OS version you can use this code:
+ (NSInteger)OSVersion
{
static NSUInteger _deviceSystemMajorVersion = -1;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_deviceSystemMajorVersion = [[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."][0] intValue];
});
return _deviceSystemMajorVersion;
}