Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the NSTextAlignment enum defined differently for TARGET_OS_IPHONE?

Tags:

ios

uikit

I was just looking at NSText.h in UIKit and the following bit of code caught my eye as being unusual

/* Values for NSTextAlignment */
typedef NS_ENUM(NSInteger, NSTextAlignment) {
    NSTextAlignmentLeft      = 0,    // Visually left aligned
#if TARGET_OS_IPHONE
    NSTextAlignmentCenter    = 1,    // Visually centered
    NSTextAlignmentRight     = 2,    // Visually right aligned
#else /* !TARGET_OS_IPHONE */
    NSTextAlignmentRight     = 1,    // Visually right aligned
    NSTextAlignmentCenter    = 2,    // Visually centered
#endif
    NSTextAlignmentJustified = 3,    // Fully-justified. The last line in a paragraph is natural-aligned.
    NSTextAlignmentNatural   = 4,    // Indicates the default alignment for script
} NS_ENUM_AVAILABLE_IOS(6_0);

Why have the values for NSTextAlignmentRight and NSTextAlignmentCenter been flipped for TARGET_OS_IPHONE vs not?

like image 328
bengoesboom Avatar asked Nov 19 '25 13:11

bengoesboom


1 Answers

Prior to iOS 6, iOS didn't have NSTextAlignment. iOS used UITextAlignment. And the Center value was 1 and the Right value was 2.

Then in iOS 6, NSTextAlignment was added. To keep backward compatibility, NSTextAlignmentCenter was given the same value as UITextAlignmentCenter. Same for Right.

It was more important that the NSTextAlignment enum on iOS matched up with the deprecated UITextAlignment than it was to be the same as the value from OS X.

The original difference between UITextAlignment on iOS and NSTextAlignment on OS X was probably a simple oversight. But that's a simple guess.

like image 113
rmaddy Avatar answered Nov 22 '25 03:11

rmaddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!