Is there any way to do this? I want to have a custom font that I've downloaded to show on ever UIButton.
If you use IBOutletCollection
then this should be direct.
@property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttons;
Connect the buttons to this outlet collection and later alter the font in a single shot using,
[self setValue:[UIFont fontWithName:@"Helvetica" size:30] forKeyPath:@"buttons.font"];
One way you could do it is to subclass UIButton setup your desired font and use your subclass instead of UIButton.
Edit
//
// MyUIButton.h
//
@interface MyUIButton : UIButton {
}
+ (id)buttonWithType:(UIButtonType)buttonType;
@end
//
// MyUIButton.m
//
#import "MyUIButton.h"
@implementation MyUIButton
+ (id)buttonWithType:(UIButtonType)buttonType{
UIButton *button = [UIButton buttonWithType:buttonType];
[[button titleLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
return button;
}
@end
Then just use it like this:
[MyUIButton buttonWithType:UIButtonTypeCustom]
The other thing you can try is writing a category for UIButton and overriding it there.
Edit2
//
// UIButton+Font.h
//
#import <Foundation/Foundation.h>
@interface UIButton (DefaultFontExtension)
+ (id)buttonWithType:(UIButtonType)buttonType;
@end
//
// UIButton+Font.m
//
#import "UIButton+Font.h"
@implementation UIButton (DefaultFontExtension)
+ (id)buttonWithType:(UIButtonType)buttonType{
UIButton *button = [UIButton buttonWithType:buttonType];
[[button titleLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
return button;
}
@end
Now just import "UIButton+Font.h" it will override the default UIButton settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With