Reputation: 337
I have an iPhone app with lots of UILabels throughout its screens. I am using Storyboards. My question is this. How can I change the font size in all of the labels in the app with a button or slider in the Settings screen? I would also like there to be a maximum size because otherwise the text will get too big for the screen.
Thanks!
Upvotes: 1
Views: 1399
Reputation: 1168
Try this:
-(IBAction)sliderValueChanged:(UISlider *)sender
{
CGFloat maxFontSize = 24.0;
CGFloat minFontSize = 8.0;
CGFloat sliderValue = sender.value;
if ((sliderValue < maxFontSize) && (sliderValue > minFontSize)) {
label1.font = [UIFont boldSystemFontOfSize:sliderValue];
label2.font = [UIFont boldSystemFontOfSize:sliderValue];
label3.font = [UIFont boldSystemFontOfSize:sliderValue];
}
}
I didn't tested this code but I think it should work.. Hope that helps.
Upvotes: 2
Reputation: 4783
Well. There isn't a fantastic way to do this. If you are looking for a quick shortcut, you're out of luck. You will need to create a method that you can run in each viewControllers viewDidLoad:
method, but first do this:
First, somewhere in your app have a slider. Say the slider ranges from 1-5. For every value after 1, save an int somewhere that you can refer to later. In any file will do. See NSCoding. Essentially, you take the number, in this case 5, and subtract one and save that. So, if the user chose 5 you would save 4.
Okay, now in each controllers viewDidLoad, have a similar method that does the following:
Get the int value that you saved. Now take your base text size and add the number you saved. You will need that as a CGFloat later. I'm not positive on how to use it, but you can find out.
Then use:
[label1 setFont:[UIFont fontWithName:@"Name Of font" size:<#(CGFloat)#>]]
You will have to use that on all UILabels.
If you need anything else let me know.
Upvotes: 1