Skip to content

Commit

Permalink
UIFont+WDCustomLoader
Browse files Browse the repository at this point in the history
UIFont-TTF
DynamicFontControl
  • Loading branch information
Jakey authored and Jakey committed Jun 22, 2015
1 parent 3af67c9 commit 49ea038
Show file tree
Hide file tree
Showing 12 changed files with 670 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Categories/UIKit/UIFont/UIFont+DynamicFontControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// UIFont+DynamicFontControl.h
//
// Created by Michael Kral on 10/28/13.
// Copyright (c) 2013 Michael Kral. All rights reserved.
//

/**
* @Author(作者) Michael Kral
*
* @URL(地址) https://github.com/mkral/UIFont-DynamicFontControlDemo
*
* @Version(版本) 20150622
*
* @Requirements(运行要求)
*
* @Description(描述) Simple Category for using UIFontTextStyle with other Fonts.
*
* @Usage(使用) ..
*/

#import <UIKit/UIKit.h>

@interface UIFont (DynamicFontControl)


+(UIFont *)preferredFontForTextStyle:(NSString *)style withFontName:(NSString *)fontName scale:(CGFloat)scale;

+(UIFont *)preferredFontForTextStyle:(NSString *)style withFontName:(NSString *)fontName;



-(UIFont *)adjustFontForTextStyle:(NSString *)style;

-(UIFont *)adjustFontForTextStyle:(NSString *)style scale:(CGFloat)scale;



@end
55 changes: 55 additions & 0 deletions Categories/UIKit/UIFont/UIFont+DynamicFontControl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// UIFont+DynamicFontControl.m
//
// Created by Michael Kral on 10/28/13.
// Copyright (c) 2013 Michael Kral. All rights reserved.
//

#import "UIFont+DynamicFontControl.h"

@implementation UIFont (DynamicFontControl)

+(UIFont *)preferredFontForTextStyle:(NSString *)style withFontName:(NSString *)fontName{
return [UIFont preferredFontForTextStyle:style withFontName:fontName scale:1.0f];
}

+(UIFont *)preferredFontForTextStyle:(NSString *)style withFontName:(NSString *)fontName scale:(CGFloat)scale{


UIFont * font = nil;
if([[UIFont class] resolveClassMethod:@selector(preferredFontForTextStyle:)]){
font = [UIFont preferredFontForTextStyle:fontName];
}else{
font = [UIFont fontWithName:fontName size:14 * scale];
}


return [font adjustFontForTextStyle:style];

}

-(UIFont *)adjustFontForTextStyle:(NSString *)style{
return [self adjustFontForTextStyle:style scale:1.0f];
}

-(UIFont *)adjustFontForTextStyle:(NSString *)style scale:(CGFloat)scale{

UIFontDescriptor * fontDescriptor = nil;

if([[UIFont class] resolveClassMethod:@selector(preferredFontForTextStyle:)]){

fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:style];

}else{

fontDescriptor = self.fontDescriptor;

}

float dynamicSize = [fontDescriptor pointSize] * scale + 3;

return [UIFont fontWithName:self.fontName size:dynamicSize];

}

@end
76 changes: 76 additions & 0 deletions Categories/UIKit/UIFont/UIFont+WDCustomLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// UIFont+WDCustomLoader.h
//
// Created by Walter Da Col on 10/17/13.
// Copyright (c) 2013 Walter Da Col (walter.dacol<at>gmail.com)
//

/**
* @Author(作者) Walter Da Col
*
* @URL(地址) https://github.com/daktales/UIFontWDCustomLoader
*
* @Version(版本) 20150622
*
* @Requirements(运行要求)
*
* @Description(描述) An iOS custom font loader
*
* @Usage(使用) ..
*/

#import <UIKit/UIKit.h>

/**
You can use `UIFont+WDCustomLoader` category to load custom fonts for your
application without worring about plist or real font names.
*/
@interface UIFont (WDCustomLoader)

/// @name Implicit registration and font loading

/**
Get `UIFont` object for the selected font file.
This method calls `+customFontWithURL:size`.
@deprecated
@see +customFontWithURL:size: method
@param size Font size
@param name Font filename without extension
@param extension Font filename extension (@"ttf" and @"otf" are supported)
@return `UIFont` object or `nil` on errors
*/
+ (UIFont *) customFontOfSize:(CGFloat)size withName:(NSString *)name withExtension:(NSString *)extension;

/**
Get `UIFont` object for the selected font file (*.ttf or *.otf files).
The first call of this method will register the font using
`+registerFontFromURL:` method.
@see +registerFontFromURL: method
@param fontURL Font file absolute url
@param size Font size
@return `UIFont` object or `nil` on errors
*/
+ (UIFont *) customFontWithURL:(NSURL *)fontURL size:(CGFloat)size;

/// @name Explicit registration

/**
Allow custom fonts registration.
With this method you can load all supported font file: ttf, otf, ttc and otc.
Font that are already registered, with this library or by system, will not be
registered and you will see a warning log.
@param fontURL Font file absolute url
@return An array of postscript name which represent the file's font(s) or `nil`
on errors. (With iOS < 7 as target you will see an empty array for collections)
*/
+ (NSArray *) registerFontFromURL:(NSURL *)fontURL;



@end
Loading

0 comments on commit 49ea038

Please sign in to comment.