2019年4月8日 星期一

改變UISegmentedControl的font

#import "UISegmentedControl+Font.h"

@implementation UISegmentedControl(Font)

- (void)setFont:(UIFont *)font color:(UIColor *)color {
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, [UIColor blackColor], NSForegroundColorAttributeName, nil];
    [self setTitleTextAttributes:attributes forState:UIControlStateNormal];
    NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    [self setTitleTextAttributes:highlightedAttributes forState:UIControlStateSelected];
}

@end