Arash Zeinoddini
Arash Zeinoddini

Reputation: 819

Difference between UITextAlignmentCenter and NSTextAlignmentCenter

What is difference between NSLineBreakByWordWrapping and UILineBreakModeWordWrap ?

For example when I used this code:

button.titleLabel.textAlignment = UITextAlignmentCenter;

Xcode said:

UITextAlignmentCenter is deprecated: first deprecated in iOS 6.0

But when I use NSTextAlignmentCenter, it was fine - so what can be the reason?

Upvotes: 2

Views: 3944

Answers (4)

Emmanuel Crombez
Emmanuel Crombez

Reputation: 305

The raison is :

  • UITextAlignmentCenter is only for IOS
  • NSTextAlignmentCenter is for IOS and MacOSX

Apple want help/push IOS developper to develop for MacOSX too.

Upvotes: 0

Deepak Kumar
Deepak Kumar

Reputation: 1044

Here's Solution with example :

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

UILabel* your_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
label.text = @"CENTER TEXT";
label.textAlignment = ALIGN_CENTER;
[self addSubview:your_label];

Upvotes: 0

jianpx
jianpx

Reputation: 3330

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

Upvotes: 1

Dave
Dave

Reputation: 1081

The cause s that UITextAlignment is deprecated in iOS 6 and the actual textAlignment property's type is NSTextAlignment. See: Reference

Upvotes: 4

Related Questions