Uitextview - Setting Font Not Working with iOS 6 on Xcode 5

UITextView - setting font not working with iOS 6 on XCode 5

The issue was caused by the editable property being false in the Storyboard. I have absolutely no idea why this caused the font to remain unchanged - and only on iOS 6.

attributedText not setting with UITextView

After I investigate custom font (especially arabic) is not working UITextView using attributedString, below is what I did.

I just wanted to display the text in UITextView (for About Us in my app) as it has long text and I wanted scrolling option.

Below is what I did.

  1. Add UIScrollView

  2. Add UILabel inside UIScrollView

  3. Assign text to UILabel.

    abtUsLabel.attributedText = attributedString;

  4. Make label sizeToFit

    [abtUsLabel sizeToFit];

    This is very important step, else it won't work.

  5. Set scrollview contentSize as per label height.

    [abtUsScrollView setContentSize:CGSizeMake(abtUsScrollView.frame.size.width, abtUsLabel.frame.size.height)];

Done... now if the Label is longer, we can scroll it.

Changing font size of attributed text in UITextView takes a lot of time in iOS 6 using Xcode 5

I finally fixed this problem by recreating my attributedtext again and setting it as a new attributedtext to my uitextview.

Changing Font in UITextView does not work in iOS7

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

Xcode Custom Font applied On UITextView, Not showing but if User type anything there, the User Text shows with Custom Font

Maybe my issue is the same with yours. I also use custom font for UILabel on my .xib file. If I choose Text type is "Plain", they works well. But when I change to "Attributed" text, the UILabel show default font although my custom font is also set. My solution is set custom font by codes.
Here is the code I set custom font (with attributed text):

UIFont *font = [UIFont fontWithName:@"ProximaNova-Light" size:13];
NSDictionary *attrDict = @{
NSFontAttributeName : font,
NSForegroundColorAttributeName : [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1]
};

NSMutableAttributedString *aAttrString = [[NSMutableAttributedString alloc] initWithString:_aboutTeacher.text attributes: attrDict];

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineSpacing:3.0f];
[style setAlignment:NSTextAlignmentCenter];

[aAttrString addAttribute:NSParagraphStyleAttributeName
value:style
range:NSMakeRange(0, [_aboutTeacher.text length])];

_aboutTeacher.attributedText = aAttrString;

UITextView renders custom font incorrectly in iOS 7

I debugged this issue a little, and it seems to be a bug in the way NSLayoutManager layouts the text. As other answers pointed out, UITextView is build around TextKit since iOS7, and thus uses NSLayoutManager internally to layout text. UILabel uses Core Text to layout text directly. Both eventually use Core Text to render the glyphs.

You should open a bug report with Apple and post the number so people can duplicate it. The issue has not been fixed so far in iOS7.1 betas.

As a workaround, you can replace UITextView with other Core Text alternative editors, which layout and render directly with Core Text, where the issue does not exist.

I tested SECoreTextView, and it shows the text correctly. It implements a similar API to UITextView but internally uses Core Text.

Here is how it looks after swapping UITextView with SECoreTextView:

SETextView *textView = [[SETextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithDescriptor:desc size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor whiteColor];
textView.editable = YES;

[self.view addSubview:textView];

Using Core Text, the layout issue does not exist.

TextView's font i not changing in storyboard

First you need a font to use. Download any of them in you cass its right here : http://ufonts.com/fonts/myriadpro-cond.html

After downloading drag & drop the font file (otf or ttf) into your project

Make sure you check the box next to your target or the font won’t actually get included in your app (even though it’ll probably show in Interface Builder).

Open up the Info.plist . Add a new array of strings to it: “Fonts provided by application”. Add the filenames for each font you want to use as String entries in the array. (That one ttf file you just added to your project )

Now you're good to go , select that font once again like you did in the attached image.

For more detail see this article https://grokswift.com/custom-fonts/



Related Topics



Leave a reply



Submit