当前位置 : 主页 > 手机开发 > ios >

ios常用宏定义

来源:互联网 收集:自由互联 发布时间:2021-06-11
// 十六进制转rgb #define ColorWithHexString(hexString) [UIColor colorWithHexString:hexString] // 获取RGB颜色 #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a] #define RGB(r,g,b) RGBA(r,g,b,1
分享图片
//十六进制转rgb
#define ColorWithHexString(hexString) [UIColor colorWithHexString:hexString]
// 获取RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)

//字体颜色
#define TITLE_EA_COLOR RGB(51,51,51)
#define TITLE_CD_COLOR RGB(34, 34, 34)
#define TITLE_AEC_COLOR RGB(153,153,153)
#define VIEW_BDA_COLOR RGB(241,241,241)

#define SELECT_LINE_Color RGB(216,0,8)
#define SELECT_TITLE_Color RGB(58,58,58)


#define Button_COLOR1 RGB(51,51,51)
#define LINE_COLOR RGB(168,168,168)

//颜色
#define ColorHex_333333 ColorWithHexString(@"#333333")
#define ColorHex_444444 ColorWithHexString(@"#444444")
#define ColorHex_666666 ColorWithHexString(@"#666666")
#define ColorHex_D9261C ColorWithHexString(@"#D9261C")
#define ColorHex_CCCCCC ColorWithHexString(@"#CCCCCC")//80 80 80




#import "UIColor+Tool.h"

@implementation UIColor (Tool)
//十六进制 # 十进制转 0X RGB 
+(UIColor *)colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    // 判断前缀
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    // 从六位数值中找到RGB对应的位数并转换
    NSRange range;
    range.location = 0;
    range.length = 2;
    //R、G、B
    NSString *rString = [cString substringWithRange:range];
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}
@end
ColorDefine 分享图片
//系统字体
#define FontSystem(f)                               [UIFont systemFontOfSize:f]
#define FontBoldSystem(f)                           [UIFont boldSystemFontOfSize:f]
//苹方字体
#define PingFangFont_(F) [UIFont fontWithName:@"PingFang SC" size:F]

//苹方常规
#define REGULAR_FONT(font) iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Regular" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define SEMIBOLD_FONT(font) iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Semibold" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define LIGHT_FONT(font)   iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Light" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define THIN_FONT(font)   iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Thin" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define MEDIUM_FONT(font)  iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Medium" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define HEAVY_FONT(font)  iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-Heavy" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]

#define BOLD_FONT(font)  iOS9LaterNew?[UIFont fontWithName:@"PingFangSC-bold" size:font*ScreenWithRateFor6]:[UIFont systemFontOfSize:font*ScreenWithRateFor6]
FontDefine 分享图片
#ifndef BaseDefinition_h
#define BaseDefinition_h

/获取屏幕 宽度、高度
#define SCREEN_WIDTH                                  ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT                                 ([UIScreen mainScreen].bounds.size.height)

// 弱引用
#define ZKWeakSelf __weak typeof(self) weakSelf = self;



// 防止多次调用
#define kPreventRepeatClickTime(_seconds_) static BOOL shouldPrevent; if (shouldPrevent) return; shouldPrevent = YES; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ shouldPrevent = NO; }); 
#endif
BaseDefine
上一篇:iOS手写签批
下一篇:iOS滤镜和贴纸功能
网友评论