How do I use the new iOS 6 methods to center text? - ios

My Old Code
sectorLabel.textAlignment = UITextAlignmentCenter;
Xcode is saying that textAlignment is deprecated. How do I use the new method?
Thank you

It now uses the same as the properties for the Mac.
Use NSTextAlignmentCenter instead :D
HTH

Related

Preferred Width is missing in xcode 5.1.1

I'm trying to make something like in this guide http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout,
but can't find property for UILabel named Preferred Width
Is it bug or have i done something wrong?
If you can't find it in that version of Xcode, you can do it in code
[label setPreferredMaxLayoutWidth:200.0];

iOS 8: UIButton appearance font

Trying to set UIButton's font for all buttons using appearance in iOS 8. After Googling, it appears that Apple has changed the way you do this from OS to OS. In iOS 7, this should have worked:
UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont()
But it doesn't seem to work anymore. Anyone know how you do it now?
Swift 3:
let fontRegular = UIFont(name: "MyCustomRegularFont", size: 17.0)
UILabel.appearance(whenContainedInInstancesOf: [UIButton.self]).font = fontRegular
UIButton.appearance().tintColor = UIColor.red
The proxy for font was removed from UILabel.appearance(), so that's the reason why this not works.
Use the appearance when contained in method on UILabel
UILabel.appearanceWhenContainedInInstancesOfClasses([UIButton.self]).font = UIFont.inviteButtonTitleFont()
This should work in iOS9, see this answer appearanceWhenContainedIn in Swift for iOS8 and 7 workarounds.
(Disclaimer, I have not compiled the code snippet so beware of typos).

TTTAttributedLabel linebreakmode broken in iOS6

If I set linebreakmode to truncation tail in the TTTAttributedLabel Example App "Espresso" everything looks like it should be in iOS 5 Simulator but if I run the App in iOS 6 Simulator the text gets truncated after the first line although the text goes over 3 lines. Number of lines are set to zero. Did I miss something? After I noticed this behavior in the Espresso App I can stop worrying about the brokeness of the code in my own app.
Any suggestions? Thanks!
I currently faced the same problem. Try setting the LineBreakMode before you actually set your text. E.g.:
TTTAttributedLabel* descriptionLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(20, 120, 280, expectedSize.height)];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
descriptionLabel.text = description;
Labels and textviews in iOS 6 support attributed text natively. So if you don't need to support older versions of iOS, you can get rid of 3rd party control.
In my case, for some reason following code was causing the label to show only one row. Removing it helped
' self.attributedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;'
Strangely the problem solved itself. I could not figure out why this particular problem happened on iOS6 Simulator but now it works with NSLineBreakTailTruncation on iOS6 Device and Simulator.
Thank you for your responses!
You can have a try.
NSMutableAttributedString * mutableAttributedString = [[NSMutableAttributedString alloc]initWithString:text];
[self.attributedLabel setText:mutableAttributedString afterInheritingLabelAttributesAndConfiguringWithBlock:nil];

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

Minimum Font Size deprecated on ios version 6.0

I just upgraded to xcode 4.5 with iOS 6.0 and it's highlighting a warning on all the UILabels in my XIB files saying "minimum font size deprecated on ios version 6.0". Does anyone know what this is referring to and how to fix it?
Update:
image is no more available (was at https://skitch.com/hahmadi82/eyk51/cloud)
minimumFontSize property of the UILabel is deprecated from iOS 6.0 onwards.
An Alternative to the minimumFontSize is minimumScaleFactor. If you assign minimumFontSize/defaultFontSize to minimumScaleFactor, it works in the same way as minimumFontSize.
The Code is as follows - For Example the font size is 30.0 and if you want the minimum font size to be 12.0
YOURLABEL.font= [UIFont fontWithName:#"FONT_NAME" size:30.0];
[YOURLABEL setMinimumScaleFactor:12.0/[UIFont labelFontSize]];
Use minimumScaleFactor instead...
Link
Quick fix...Here minimum font size to be 8.0
CGFloat size = textLabel.font.pointSize;// font size of label text
[textLabel setMinimumScaleFactor:8.0/size];
I am answering very late, but might help any other.
As every one knows that setMinimumFontSize has been deprecated, so other method replacing setMinimumFontSize is setAdjustFontToFitWidth which takes BOOL
e.g
[yourLabel setAdjustsFontSizeToFitWidth:YES];
//or
yourLabel.adjustsFontSizeToFitWidth = YES;
For Swift use the following:
//set the number (ex. 8 to your desired minimum font size)
myLabel!.minimumScaleFactor = 8/myLabel!.font.pointSize;`
Works like a charm!
I had similar problem. Quick fix is to use MinimumScaleFactor property of UILabel.
Go into finder and find the .storyboard file or your .xib and open with TextEdit. Use find to locate the string "autoshrinkMode" and replace the value "minimumFontSize" to "minimumFontScale"
Odd that the conversion wasn't written in the update scripts...
Also credit to #Rob in the comments above for stating the same answer. He should receive credit for this one.
You can use minimum scale factor over there or drag a lable and set autoshrik-> minimum font.
Maybe this can help you.
Yes minumumFontSize is deprecated.
Use following minimumScaleFactor:-
Obj.minimumScaleFactor= (floatValue);

Resources