What are good alternatives to UITextAlignmentCente

2019-02-02 19:46发布

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

标签: ios6
5条回答
来,给爷笑一个
2楼-- · 2019-02-02 19:52

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

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

查看更多
老娘就宠你
3楼-- · 2019-02-02 19:57

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
查看更多
家丑人穷心不美
4楼-- · 2019-02-02 19:58
#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];
查看更多
ら.Afraid
5楼-- · 2019-02-02 20:04

In Swift: NSTextAlignment.Center

查看更多
Deceive 欺骗
6楼-- · 2019-02-02 20:10

You can do

newLabel.textAlignment = NSTextAlignmentCenter;

instead of

newLabel.textAlignment = UITextAlignmentCenter;

hope it helps.

查看更多
登录 后发表回答