What are good alternatives to UITextAlignmentCenter in iOS 6?

Ios6

Ios6 Problem Overview


UITextAlignmentCenter seems to be deprecated in iOS 6. What are my alternatives?

Ios6 Solutions


Solution 1 - Ios6

For IOS 6 you should use NSTextAlignmentCenter instead of UITextAlignmentCenter:

button.titleLabel.textAlignment = NSTextAlignmentCenter;

Source

And if you want backward compatibiliy to IOS 5 also you can do this,

#ifdef __IPHONE_6_0
# define ALIGN_CENTER NSTextAlignmentCenter
#else
# define ALIGN_CENTER UITextAlignmentCenter
#endif

Solution 2 - Ios6

#ifdef __IPHONE_6_0
# define ALIGN_CENTER NSTextAlignmentCenter
#else
# define ALIGN_CENTER UITextAlignmentCenter
#endif

UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
label.text = @"There is no spoon";
label.textAlignment = ALIGN_CENTER;
[self addSubview:label];

Solution 3 - Ios6

You can do

newLabel.textAlignment = NSTextAlignmentCenter;

instead of

newLabel.textAlignment = UITextAlignmentCenter;

hope it helps.

Solution 4 - Ios6

You should use NSTextAlignmentCenter instead according to Apple's documentation.

You should also use NSTextAlignmentLeft and NSTextAlignmentRight instead of UITextAlignmentLeft and UITextAlignmentRight, respectively.

Solution 5 - Ios6

In Swift: NSTextAlignment.Center

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIOS_DevView Question on Stackoverflow
Solution 1 - Ios6NiKKiView Answer on Stackoverflow
Solution 2 - Ios6Arash ZeinoddiniView Answer on Stackoverflow
Solution 3 - Ios6iEinsteinView Answer on Stackoverflow
Solution 4 - Ios6zachjsView Answer on Stackoverflow
Solution 5 - Ios6Pradeep RajkumarView Answer on Stackoverflow