IOS_Dev
IOS_Dev

Reputation: 655

What are good alternatives to UITextAlignmentCenter in iOS 6?

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

Upvotes: 53

Views: 32075

Answers (5)

Pradeep Rajkumar
Pradeep Rajkumar

Reputation: 937

In Swift: NSTextAlignment.center

Upvotes: 3

NiKKi
NiKKi

Reputation: 3296

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

Upvotes: 103

zachjs
zachjs

Reputation: 1748

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

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

Upvotes: 4

iEinstein
iEinstein

Reputation: 2100

You can do

newLabel.textAlignment = NSTextAlignmentCenter;

instead of

newLabel.textAlignment = UITextAlignmentCenter;

hope it helps.

Upvotes: 7

Arash Zeinoddini
Arash Zeinoddini

Reputation: 819

#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];

Upvotes: 9

Related Questions