0

I have a relatively small native app that and would like to have a 3-button control that can set the font size application wide. I'd like it to be able to support clicking the different unfilled-in size and have it automatically rerender the current view with the new font size and all subsequent views. Similar to having a control where the filled-in size is the current size and the clear versions would be buttons that could be selected:

enter image description here

It would seem like I want to pogramaticaslly have Dynamic Type but I'm not sure if there is an easier way. Reading through the different Text technologies really hasn't provided much help.

My views use a combination of UILabels and UITextViews with NSAttributedString's and NSString's. What would be the best option to manage font size programatically?

thx for any help

edit 1

Here's a label that I would like to add; can I just update the _mainFont variable which is used in the subviews and tell those subviews to update their rendering?

   UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 100.0f, 20.0f)];
    myLabel.backgroundColor = [UIColor blueColor];
    [myLabel setUserInteractionEnabled:YES];

    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [recognizer setNumberOfTapsRequired:1];
    //lblName.userInteractionEnabled = true;  (setting this in Interface Builder)
    [myLabel addGestureRecognizer:recognizer];

    [tempScrollView addSubview:myLabel];

}

- (void)tapAction {
    NSLog(@"Tap action");
    _mainFont = MYLargerMainFont();
    [self.view setNeedsDisplay];
    //[self.view.subviews setNeedsDisplay];

}
timpone
  • 19,235
  • 36
  • 121
  • 211

2 Answers2

0

The answers in the questions below might give you some ideas:

Community
  • 1
  • 1
Legoless
  • 10,942
  • 7
  • 48
  • 68
  • thx @Legoless so we are specifying a custom font to start with (Helvetica-Neue 18pt) and will probably have the larger be 24pt and 36pt or something. The issue isn't setting custom font but updating the app in all the places. – timpone Mar 12 '14 at 08:28
  • I believe you could use UIAppearance methods for this. Did you try that? – Legoless Mar 12 '14 at 08:43
  • I don't think I can set a UIAppearance proxy to, for example, a specific UILabel. http://stackoverflow.com/questions/11839044/how-do-i-apply-uiappearance-proxy-properties-to-uilabel agree with the comment that this is mind-boggling. – timpone Mar 12 '14 at 16:16
0

Just like Dynamic Type, it seems the best approach would be to fire a notification when the change happens, and have view controllers listen to this change and set the fonts. If you want something more robust, you could create subclasses of the UI elements you have and have them listen to font size change notifications, and update themselves accordingly. I like the former approach, because it is the view controller that should ultimately have control over the views.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • thx Leo - so do something like write the currently selected font size to NSUserDefaults and then in viewDidLoad get it and set the font in the appropriate places? This is a small app so that would only be setting in like 10 or 12 places which is ok. For the currently selected, maybe just use a NSNotification event? Sorry for more questions, I'm not full-time iOS dev. – timpone Mar 12 '14 at 08:39
  • @timpone Yes, that's exactly it. It works the same when attempting to use the system API for Dynamic Type. When you load, you read the value saved, and when the user changes the size in settings, a system-wide notification is sent to all apps that the size changed. – Léo Natan Mar 12 '14 at 08:44
  • thx - yeah this will all be within app so the user will never be going to settings. Perhaps I can do the code in the edit above? I appreciate the help as I'm not full-time iOS dev and just want to figure out how to get this done. thx again – timpone Mar 12 '14 at 17:04