Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good alternatives to UITextAlignmentCenter in iOS 6?

Tags:

ios6

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

like image 686
IOS_Dev Avatar asked Oct 09 '12 04:10

IOS_Dev


5 Answers

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
like image 86
NiKKi Avatar answered Sep 28 '22 03:09

NiKKi


#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];
like image 38
Arash Zeinoddini Avatar answered Sep 29 '22 03:09

Arash Zeinoddini


You can do

newLabel.textAlignment = NSTextAlignmentCenter;

instead of

newLabel.textAlignment = UITextAlignmentCenter;

hope it helps.

like image 33
iEinstein Avatar answered Sep 28 '22 03:09

iEinstein


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

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

like image 33
zachjs Avatar answered Sep 27 '22 03:09

zachjs


In Swift: NSTextAlignment.Center

like image 45
Pradeep Rajkumar Avatar answered Sep 25 '22 03:09

Pradeep Rajkumar