xcode 如何在 iOS 6.0 中进行文本对齐?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13873946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do text alignment in iOS 6.0 ?
提问by Shivaay
I am using the below code to get text but i dont know how to do text alignment in iOS 6.0..So,Please someone Help me...
我正在使用下面的代码来获取文本,但我不知道如何在 iOS 6.0 中进行文本对齐......所以,请有人帮助我......
cell.textLabel.font=[UIFont fontWithName:@"Arial" size:16.0];
cell.textLabel.textColor=[UIColor colorWithRed:15.0/255.0 green:122.0/255.0 blue:202.0/255.0 alpha:1.0];
cell.textLabel.text=[titleArray objectAtIndex:indexPath.row];
回答by Shivaay
finally after a lot of research i found the answer of my question...
终于经过大量的研究,我找到了我的问题的答案......
label5.textAlignment = NSTextAlignmentLeft;
tnx to all who helped me...
感谢所有帮助过我的人...
回答by alexiscrack3
This is what you need to do in iOS Devices
这是您需要在 iOS 设备中执行的操作
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textAlignment = UITextAlignmentCenter;
If your are developing something for MAC, you should use:
如果你正在为 MAC 开发一些东西,你应该使用:
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
Assign Alignment accordingly.
相应地分配对齐。
回答by NiravPatel
cell.textLabel.textAlignment=NSTextAlignmentLeft;//or whatever you want buddy
let me know it is working or not...
让我知道它是否有效...
回答by sumon
You can use the following code:
您可以使用以下代码:
cell.textLabel.textAlignment = NSTextAlignmentCenter;
Hope this helps.
希望这可以帮助。
Please try with another label and add it to the cell:
请尝试使用另一个标签并将其添加到单元格中:
Write the following code on top of the class:
在类的顶部编写以下代码:
#ifdef __IPHONE_6_0
# define ALIGN_CENTER NSTextAlignmentCenter
#else
# define ALIGN_CENTER UITextAlignmentCenter
#endif
Then add a label:
然后添加一个标签:
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
label.text = @"This is a sample text";
label.textAlignment = ALIGN_CENTER;
[cell.contentView addSubview:label];
[label release];
Is it works?
它有效吗?
回答by NiravPatel
try this man...let see working or not...
试试这个人...让看看工作与否...
write below statement in your common file (for example constant.h)
在您的公共文件中写下以下语句(例如constant.h)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
//then to check textalignment for ios 6 or ios 5 write below code .m file where you want to use
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
cell.textLabel.textAlignment=NSTextAlignmentLeft;
}
else
{
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
try this ...
尝试这个 ...
Happy Coding!!!!!
快乐编码!!!!!