Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Font in UITextView does not work in iOS7

I have a UITextView with text in it, the View is in a UITableViewCell. I noticed that the font was not quite the same on iOS7 as with iOS6, noting it was set to "system" I decided to specify the exact font/size.

It appeared nothing happened so I thought I would do a better test (big font not used anywhere), like this in my "CellForRowAt....";

cell.newsItemDescription.font = [UIFont fontWithName:@"didot" size:20];
cell.newsItemDescription.text = newsDescriptions[indexPath.row];

In iOS6 it comes out like this;

Screen Shot from iOS6

In iOS7 it comes out like this;

enter image description here

It happens in just a few places in the app but it is very annoying, can't figure out why? I am fast getting to the point where I may use the iOS7 Font/ Size throughout the app.

Some extra info;
The UITextView is resized per cell along with the cell (using springs/struts, i.e. no Auto Layout) and HeightForRow...

The font was setup in Storyboard originally (as system)

This is the same on devices and Simulator

like image 370
Recycled Steel Avatar asked Oct 10 '13 09:10

Recycled Steel


2 Answers

I have a strange behavior in iOS 7. Font is smaller than I expect, if I was set it in to the xib.

If I set font after setting the text it's works for me. Otherwise font is smaller.

Try this:

  cell.newsItemDescription.text = newsDescriptions[indexPath.row];
  cell.newsItemDescription.font = [UIFont fontWithName:@"didot" size:20];
like image 168
AlKozin Avatar answered Oct 22 '22 13:10

AlKozin


I had the same issue today with UITextView, and while reading AlKozin's answer, I remembered something: somewhere, sometime I read that since iOS 7, the best practice to set font styles is to set them after the View has loaded. In other words, if I set everything in viewDidLoad: , nothing happens. You have to set up the font of your UITextView in viewWillAppear:, like this:

-(void)viewWillAppear:(BOOL)animated
{
     self.myTextView.font = [UIFont fontWithName:@"Baskerville-Italic" size:18.0];
}
like image 44
suntime Avatar answered Oct 22 '22 11:10

suntime