1

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...

        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];
Kundan
  • 3,084
  • 2
  • 28
  • 65

5 Answers5

8

finally after a lot of research i found the answer of my question...

label5.textAlignment = NSTextAlignmentLeft;

tnx to all who helped me...

Kundan
  • 3,084
  • 2
  • 28
  • 65
5

This is what you need to do in iOS Devices

cell.textLabel.textAlignment = UITextAlignmentCenter;

If your are developing something for MAC, you should use:

cell.textLabel.textAlignment = NSTextAlignmentCenter;

Assign Alignment accordingly.

Meet
  • 4,904
  • 3
  • 24
  • 39
alexiscrack3
  • 148
  • 1
  • 7
1
 cell.textLabel.textAlignment=NSTextAlignmentLeft;//or whatever you want buddy

let me know it is working or not...

Hemang
  • 1,224
  • 9
  • 15
NiravPatel
  • 3,260
  • 2
  • 21
  • 31
0

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?

sumon
  • 742
  • 1
  • 11
  • 33
  • can you please see this link: http://stackoverflow.com/questions/11920321/label-alignment-in-ios-6-uitextalignment-deprecated please read this thread + what you are getting now ? any error or no changes regarding the code ? + are you getting right output for label color and the font also ? – sumon Dec 14 '12 at 06:54
  • are you testing in simulator? Is it iPhone 6.0 simulator ? It should work and the issue is also simple. Please don't be frustrated! I think you can solve your problem, can you please recheck the code and ensure that there is no duplicate alignment code + which alignment are you expecting ? Left, right or center? – sumon Dec 14 '12 at 07:06
  • I have edited the answer, can you please check with another label and check that is it working or not. thanks. – sumon Dec 14 '12 at 07:16
0

try this man...let see working or not...

write below statement in your common file (for example 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!!!!!

NiravPatel
  • 3,260
  • 2
  • 21
  • 31