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.

8
  • Have you checked the objects and properties you are using is also available in IOS 6 ? Commented Mar 15, 2014 at 9:35
  • NSMutableAttributedString working for > iOS6 Commented Mar 15, 2014 at 9:36
  • @iPatel : yes my app is iOS 6+ (iOS 6, iOS 7) Commented Mar 15, 2014 at 9:38
  • @iPatel : any idea how to get it working for UITextView (for iOS 6)? Commented Mar 15, 2014 at 9:47
  • 1
    possible duplicate of UITextView - setting font not working with iOS 6 on XCode 5 Commented Mar 15, 2014 at 9:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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)).
actually chances of scrolling is less and even if scrolling is needed, max 2 times scrolling will be there
@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?
@user2335125 : May be this solution will help you Regarding document, I don't have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.