Question

I am trying to set custom font.

Font is working with UILabel.

When I tries to use for UITextView, its not working. UITextView is taking default font.

Any idea how to use custom font for UITextView.

Code I am using is as below.

attributedString = [[NSMutableAttributedString alloc] initWithString:text
    attributes:@{ NSFontAttributeName : [UIFont fontWithName:@"GEDinarOne-Medium" 
    size:15], NSLigatureAttributeName: @2}];
abtUsText.attributedText = attributedString;
abtUsText.textAlignment = NSTextAlignmentRight;
abtUsText.textColor = cb60756;

I am using attributedString to get working with iOS 6.

iOS 7 is giving proper font, but iOS 6 is using default font for UITextView only.

Edit 1

I am using arabic font as GEDinarOne-Medium


Edit 2

This is not duplicate of what is mentioned above as my case is with arabic font and not english font. Mentioned in duplicate works with english custom fonts only.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top