0

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.

Surfer
  • 1,370
  • 3
  • 19
  • 34
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

1 Answers1

1

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.

Surfer
  • 1,370
  • 3
  • 19
  • 34
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • Glad that you've found a solution which is working for you. However, please keep in mind that UILabels are not perfect for long text. If you reach a certain length, the label won't be drawn completely / partially (as UILabel will render the complete text into the graphic buffer and there are limitations (graphic memory)). – cweinberger Mar 16 '14 at 10:23
  • actually chances of scrolling is less and even if scrolling is needed, max 2 times scrolling will be there – Fahim Parkar Mar 16 '14 at 10:57
  • @FahimParkar hmm, you are right about custom fonts. I have the same problem with it. Do you have any document about custom fonts error with UITextView `attributedString`? – trunghvbk Jan 06 '23 at 01:23
  • 1
    @user2335125 : [May be this solution will help you](https://stackoverflow.com/a/19168661/1066828) Regarding document, I don't have. – Fahim Parkar Jan 08 '23 at 06:06