IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    为UIFont增加一个Category

    键盘上的舞者发表于 2016-10-22 14:46:34
    love 0

    在IOS开发中,经常需要使用到UIFont类,那么我们就来对这些系统提供的类进行一些简易的封装,来更一步的简化使用它们。

    给UIFont添加一个Category

    //
    //  UIFont+Fonts.h
    //  POP动画
    //
    //  Created by 键盘上的舞者 on 10/20/16.
    //  Copyright © 2016 键盘上的舞者. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UIFont (Fonts)
    
    #pragma mark - Added font.
    
    /**
     *  HYQiHei-BEJF font (added by plist).
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)HYQiHeiWithFontSize:(CGFloat)size;
    
    #pragma mark - System font.
    
    /**
     *  AppleSDGothicNeo-Thin font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)AppleSDGothicNeoThinWithFontSize:(CGFloat)size;
    
    /**
     *  Avenir font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)AvenirWithFontSize:(CGFloat)size;
    
    /**
     *  Avenir-Light font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)AvenirLightWithFontSize:(CGFloat)size;
    
    /**
     *  Heiti SC font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)HeitiSCWithFontSize:(CGFloat)size;
    
    /**
     *  HelveticaNeue font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)HelveticaNeueFontSize:(CGFloat)size;
    
    /**
     *  HelveticaNeue-Bold font.
     *
     *  @param size Font's size.
     *
     *  @return Font.
     */
    + (UIFont *)HelveticaNeueBoldFontSize:(CGFloat)size;
    
    @end

    //
    //  UIFont+Fonts.m
    //  POP动画
    //
    //  Created by 键盘上的舞者 on 10/20/16.
    //  Copyright © 2016 键盘上的舞者. All rights reserved.
    //
    
    #import "UIFont+Fonts.h"
    
    @implementation UIFont (Fonts)
    
    #pragma mark - Added font.
    
    + (UIFont *)HYQiHeiWithFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"HYQiHei-BEJF" size:size];
    }
    
    #pragma mark - System font.
    
    + (UIFont *)AppleSDGothicNeoThinWithFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"AppleSDGothicNeo-Thin" size:size];
    }
    
    + (UIFont *)AvenirWithFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"Avenir" size:size];
    }
    
    + (UIFont *)AvenirLightWithFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"Avenir-Light" size:size];
    }
    
    + (UIFont *)HeitiSCWithFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"Heiti SC" size:size];
    }
    
    + (UIFont *)HelveticaNeueFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"HelveticaNeue" size:size];
    }
    
    + (UIFont *)HelveticaNeueBoldFontSize:(CGFloat)size {
        
        return [UIFont fontWithName:@"HelveticaNeue-Bold" size:size];
    }
    
    
    @end

     



沪ICP备19023445号-2号
友情链接