user1724168
user1724168

Reputation:

Compatibility of ios5 and ios6

I have a problem regarding incompatibility of ios5 vs ios6

While I was working on my project with ios5

label.textAlignment = UITextAlignmentCenter;

then updated to ios6

label.textAlignment = NSLineBreakByTruncatingTail;

Once I run my code on the device which ios5 installed, that give me error.

I am about to upload my app to appstore, however I want my app also supports ios5 as well. How I am going to handle both ios5 and ios6!

Thanks in advance!

Upvotes: 0

Views: 1971

Answers (1)

Tommy
Tommy

Reputation: 100622

The acceptable values for NSTextAlignment are:

  • NSTextAlignmentLeft
  • NSTextAlignmentCenter
  • NSTextAlignmentRight
  • NSTextAlignmentJustified
  • NSTextAlignmentNatural

Of those any of the first three will work equally under iOS 5 and 6.

NSLineBreakByTruncatingTail isn't really a valid type of text alignment though it'll look like NSTextAlignmentNatural at runtime because of the way the C enums line up.

So you'll need either to switch to NSTextAlignmentLeft across the board or to do a functionality check. Thankfully the change in text alignment type is in support of the new ability to push attributed strings to UILabel (and elsewhere) so that gives you something to hang off.

E.g.

if([label respondsToSelector:@selector(attributedText)])
    label.textAlignment = NSTextAlignmentNatural;
else
    label.textAlignment = NSTextAlignmentLeft;

Though the else is technically redundant because NSTextAlignmentLeft is the default value.

Upvotes: 1

Related Questions