iOS 常用宏

// --------------屏幕宽高--------------------

#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)

#define Screenheight ([UIScreen mainScreen].bounds.size.height)


// button边框

#define BUTTON_BODER(button,width,color)\

button.layer.borderColor = color.CGColor;\

button.layer.borderWidth = width;


// 弱引用 weakSelf

#define K_WEAK_SELF __weak __typeof(&*self)weakSelf = self


// button添加点击事件

#define BTN_MSG_FUNC(btn,func) [btn addTarget:self action:@selector(func) forControlEvents:UIControlEventTouchUpInside]


// 图片添加点击事件

#define IMAGE_FUNC(image,func) [image setUserInteractionEnabled:YES];\

[image addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(func)]];



/**  右按钮 文字  */

#define Right_Item_text(name,rightAction)\

UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:name style:(UIBarButtonItemStyleDone) target:self action:@selector(rightAction)];\

self.navigationItem.rightBarButtonItem = item;


/**  右按钮 图片  */

#define Right_Item_Image(Imagename,selector)\

UIBarButtonItem *litem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:Imagename] style:(UIBarButtonItemStyleDone) target:self action:@selector(selector)];\

self.navigationItem.rightBarButtonItem = litem;


// 视图旋转

#define VIEW_Transform(view,Transform)\

[view setTransform:CGAffineTransformMakeRotation(M_PI * Transform)];


// 圆角宏 Radius传角度

#define VIEW_RADIUS(View, Radius)\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES]


// 圆形

#define VIEW_YuanJiao(View)\

[View.layer setCornerRadius:(View.frame.size.height/2)];\

[View.layer setMasksToBounds:YES]


//----------------------图片---------------------------

//读取本地图片

#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定义UIImage对象

#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]


//全屏背景图

#define BACK_IMAGE(view,imageName)\

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];\

imageView.frame=CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);\

[view addSubview:imageView];\

[view sendSubviewToBack:imageView];


//背景图+frame

#define BACK_IMAGE_FRAME(view,imageName,cgrctFrame)\

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];\

imageView.frame=cgrctFrame;\

[view addSubview:imageView];\

[view sendSubviewToBack:imageView];


//----------------------颜色---------------------------


// 获取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 WZYRandomColor [UIColor colorWithRed:arc4random_uniform(256) /255.0 green:arc4random_uniform(256) /255.0 blue:arc4random_uniform(256) /255.0 alpha:1]


//随机色透明度

#define WZYRandomColorWithAlpha(a) [UIColor colorWithRed:arc4random_uniform(256) /255.0 green:arc4random_uniform(256) /255.0 blue:arc4random_uniform(256) /255.0 alpha:(a)]


//清除背景色

#define CLEARCOLOR [UIColor clearColor]


// 按照像素处理值自适应屏幕用

#define SNRealValue(value) ((value)/375.0f*[UIScreen mainScreen].bounds.size.width)


//________________系统相关____________________

//获取系统版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]


#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]


#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)


//#define IOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 9.0)

#define IOS8_10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 && [[UIDevice currentDevice].systemVersion doubleValue] < 10.0)

#define IOS10 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)


//获取当前语言

#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])


/**  是否ipad  */

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)


//单例化一个类

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \

static classname *shared##classname = nil; \

+ (classname *)shared##classname \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [[self alloc] init]; \

} \

} \

return shared##classname; \

} \

+ (id)allocWithZone:(NSZone *)zone \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [super allocWithZone:zone]; \

return shared##classname; \

} \

} \

return nil; \

} \

- (id)copyWithZone:(NSZone *)zone \

{ \

return self; \

}



//----------------------颜色类---------------------------

// 16进制颜色

#define UIColorFromValue16(value16) [UIColor \

colorWithRed:((float)((value16 & 0xFF0000) >> 16))/255.0 \

green:((float)((value16 & 0xFF00) >> 8))/255.0 \

blue:((float)(value16 & 0xFF))/255.0 alpha:1.0]

// aqua 浅蓝

#define qianLanColor [UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:1.000]

// sky 天蓝

#define tianLanColor [UIColor colorWithRed:0.400 green:0.800 blue:1.000 alpha:1.000]

// 浅红

#define qianHongColor [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000]

// 蓝紫色

#define lanZiColor [UIColor colorWithRed:0.400 green:0.400 blue:1.000 alpha:1.000]


#define hui1Color [UIColor colorWithWhite:0.902 alpha:1.000]// 1灰

#define hui2Color [UIColor colorWithWhite:0.800 alpha:1.000]// 2灰

#define hui3Color [UIColor colorWithWhite:0.702 alpha:1.000]// 3灰

#define hui4Color [UIColor colorWithWhite:0.600 alpha:1.000]// 4灰

#define hui5Color [UIColor colorWithWhite:0.502 alpha:1.000]// 5灰

#define hui6Color [UIColor colorWithWhite:0.498 alpha:1.000]// 6灰

#define hui7Color [UIColor colorWithWhite:0.400 alpha:1.000]// 7灰

#define hui8Color [UIColor colorWithWhite:0.298 alpha:1.000]// 8灰

#define hui9Color [UIColor colorWithWhite:0.200 alpha:1.000]// 9灰

#define hui10Color [UIColor colorWithWhite:0.098 alpha:1.000]// 10灰



#define dateFormatDefine @"yyyy-MM-dd HH:mm:ss"



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS开发中,有许多常用的库和框架可以帮助开发者提高效率和加速开发过程。以下是一些常用的库和框架: 1. Alamofire:一个简洁的网络请求库,提供了一种优雅的方式来进行网络请求和处理响应。 2. SDWebImage:一个用于异步加载和缓存网络图片的库,可以帮助提高图片加载性能,并且具有内存和磁盘缓存机制。 3. AlamofireImage:一个基于Alamofire的图片加载库,提供了一些便捷的方法来加载网络图片并进行缓存。 4. SwiftyJSON:一个轻量级的、灵活的JSON解析库,可以帮助简化处理JSON数据的过程。 5. SnapKit:一个优雅的、轻量级的Auto Layout框架,使用Swift语言提供了一种简化UI布局代码的方式。 6. Realm:一个移动数据库框架,提供了高效的数据存储和查询功能,并且支持对象关系映射(ORM)。 7. AlamofireObjectMapper:一个将Alamofire与ObjectMapper结合使用的库,可以方便地将JSON数据映射到模型对象中。 8. Kingfisher:一个用于异步加载和缓存网络图片的库,具有高性能和功能丰富的特点。 9. RxSwift:一个用于响应式编程的库,可以简化异步编程和事件处理的复杂性。 10. IQKeyboardManager:一个用于处理键盘弹出和收起的库,可以自动管理键盘,提供了一种简单的方式来避免键盘遮挡输入框的问题。 这只是一小部分常用的库和框架,iOS开发中还有许多其他优秀的工具可供选择,根据具体需求选择合适的库和框架进行开发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值