Amira Elsayed Ismail
Amira Elsayed Ismail

Reputation: 9404

set text attribue like (color, font, font size) not working in iOS

I need to apply a specific format for navigation title

I write this code

// color
    UIColor *titlecolor = [self getUIColorObjectFromHexString:@"#5C8EB3" alpha:1.0];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSForegroundColorAttributeName:titlecolor}];

    // font face
    UIFont *font=[UIFont fontWithName:@"NotoKufiArabic-Regular" size:16.0f];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:font}];

there is no problem with color, the problem is with font can anyone please tell me what is the problem ?

Upvotes: 0

Views: 51

Answers (1)

Gordonium
Gordonium

Reputation: 3487

You don't say what you're seeing, only that the setting the font doesn't work. I'm going to make a guess that the font is the problem (it might not be). But to hazard a guess, try these to see if we can narrow the problem down a bit:

  1. In your plist have you included the fonts under UIAppFonts aka Fonts provided by application?

  2. Also, have you made sure that the correct targets are selected for your custom font?

  3. Run this:

    NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]]; NSLog(@"Fonts: %@", [UIFont familyNames]);

are your fonts listed?

  1. Check the Font Book application on your mac, search for the font and find its correct name (called PostScript name). Use exactly this name to refer to the font.

  2. Is the font included in the bundle resources? (Under Build Phases -> Copy Bundle Resources.)

  3. When you added the fonts to your project, did you select 'Copy items if needed'?

  4. Are you doing this in a Launch Screens storyboard? They can't use custom fonts.

Upvotes: 2

Related Questions