2012-12-14 17 views
1

我使用下面的代碼來獲取文本,但我不知道該怎麼做iOS中6.0..So文本對齊,請幫助我的人......如何在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]; 

回答

9

最後經過了大量的研究,我發現我的問題的答案......

label5.textAlignment = NSTextAlignmentLeft; 

TNX所有誰幫我...

1
cell.textLabel.textAlignment=NSTextAlignmentLeft;//or whatever you want buddy 

讓我知道這是工作或不...

+0

試過,但沒有工作... – Shivaay

+0

是什麼發生然後我的朋友.....告訴我,..仍然存在問題..? – NiravPatel

+0

我嘗試了幾次所有可能的對齊方式,但對齊方式沒有變化 – Shivaay

0

您可以使用下面的代碼:

cell.textLabel.textAlignment = NSTextAlignmentCenter; 

希望這有助於。

請另一個標籤嘗試,並將其添加到單元:

寫在類的頂部下面的代碼:

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

然後添加一個標籤:

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

是有用?

+0

試過這個,但nt工作.. – Shivaay

+0

可以請你看看這個鏈接:http://stackoverflow.com/questions/11920321/label-alignment-in-ios-6-uitextalignment-deprecated 請閱讀此主題+你是什麼現在得到了嗎?有關代碼的任何錯誤或沒有更改? +你會得到正確的標籤顏色和字體的輸出? – sumon

+0

除了對齊,我正在獲得一切。 – Shivaay

5

這是你需要在iOS設備做什麼

cell.textLabel.textAlignment = UITextAlignmentCenter;

如果你正在開發的東西MAC,你應該使用:

cell.textLabel.textAlignment = NSTextAlignmentCenter;

相應地指定對齊。

+2

第一個和第二個之間有什麼區別? – iDev

+3

但問題是關於IOS 6,沒有使用'UITextAlignment'而不是它,我們使用'NSTextAlignment' ..... !! – TheTiger

+0

這真的不應該是最高的投票答案,因爲它僅僅是錯誤的iOS5 – Rambatino

0

試試這個男人......讓看工作或不...下面的語句

寫在共同文件(例如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; 
} 

試試這個...

快樂編碼!!!!!

+0

它顯示錯誤在此行..如果(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@「6.0」)) – Shivaay

+0

錯誤是預期的標識符或( – Shivaay

+0

它顯示的是什麼錯誤??? – NiravPatel