2

I would like to set custom font for my complete view

I have referred the following How do I set a custom font for the whole application?

But this suggests only font type and font size for the labels currently am using following code snippet for all labels which is increasing the redundancy.

label.textColor = [UIColor blueColor]; [label setBackgroundColor:[UIColor clearColor]]; 

Is it possible to add text color and background color in similar fashion ?

1
  • This question may be a duplicate of something else, but it's not a duplicate of the question it's marked as. Commented Mar 20, 2013 at 0:03

3 Answers 3

3

Try this

-(void)changeFont:(UIView *) view{ for (id View in [view subviews]) { if ([View isKindOfClass:[UILabel class]]) { [View setFont:[UIFont fontWithName:@"Candara" size:26]]; View.textColor = [UIColor blueColor]; [View setBackgroundColor:[UIColor clearColor]]; } if ([View isKindOfClass:[UIView class]]) { [self changeFont:View]; } } } 

call this methode and pass your view

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

Comments

2

If you're using iOS 5+ and have the labels inside a custom view (or can put them into a custom view) then you can use UIAppearance and UIAppearanceContainer. They are made for exactly this scenario.

The relevant method is +appearanceWhenContainedIn:, which allows you to set the appearance (font, color, background image etc.) when the view class you are targeting is contained inside a view of a given class.

// Set appearance of UILabels within MyViews [[UILabel appearanceWhenContainedIn:[MyView class], nil] setTextColor:[UIColor greenColor]]; [[UILabel appearanceWhenContainedIn:[MyView class], nil] setFont:[UIFont fontWithName:@"SourceCodePro-Black" size:24]]; 

I put this into the app delegate, but you could put it somewhere else. This will change the appearance of all UILabel instances which are inside a view of class MyView.

Check out the WWDC 2011 video for Session 114 for details.

enter image description here

Comments

1

Create a category for label like"

 @interface UILabel(SMLabelCatogary) - (void) setCustomLabelDesign; @end @implementation UILabel(SMLabelCatogary) - (void) setCustomLabelDesign{ label.textColor = [UIColor blueColor]; [label setBackgroundColor:[UIColor clearColor]]; } @end 

Now call setCustomLabelDesign with your label (as [label setCustomLabelDesign]) to customize that in this accordance.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.