美文网首页技术iOS技术点
代码适配常用分类

代码适配常用分类

作者: 季末微夏 | 来源:发表于2016-10-28 12:31 被阅读88次

前言

很多时候我们喜欢使用代码直接做适配,但是很多原生的属性写起来非常浪费时间,于是写了一个常用属性分类。

主要属性

/**
 *  UIScreen width.
 */
#define  ScreenWidth   [UIScreen mainScreen].bounds.size.width

/**
 *  UIScreen height.
 */
#define  ScreenHeight  [UIScreen mainScreen].bounds.size.height

/**
 *  Status bar height.
 */
#define  StatusBarHeight      20.f

/**
 *  Navigation bar height.
 */
#define  NavigationBarHeight  44.f

/**
 *  Tabbar height.
 */
#define  TabbarHeight         49.f

/**
 *  Status bar & navigation bar height.
 */
#define  StatusBarAndNavigationBarHeight   (20.f + 44.f)

/**
 *  iPhone4 or iPhone4s
 */
#define  iPhone4_4s     (Width == 320.f && Height == 480.f ? YES : NO)

/**
 *  iPhone5 or iPhone5s
 */
#define  iPhone5_5s     (Width == 320.f && Height == 568.f ? YES : NO)

/**
 *  iPhone6 or iPhone6s
 */
#define  iPhone6_6s     (Width == 375.f && Height == 667.f ? YES : NO)

/**
 *  iPhone6Plus or iPhone6sPlus
 */
#define  iPhone6_6sPlus (Width == 414.f && Height == 736.f ? YES : NO)

@interface UIView (SetRect)

/**
 控件起点
 */
@property (nonatomic) CGPoint viewOrigin;

/**
 控件大小
 */
@property (nonatomic) CGSize  viewSize;

/**
 控件起点x
 */
@property (nonatomic) CGFloat x;

/**
 控件起点Y
 */
@property (nonatomic) CGFloat y;

/**
 控件宽
 */
@property (nonatomic) CGFloat width;

/**
 控件高
 */
@property (nonatomic) CGFloat height;

/**
 控件顶部
 */
@property (nonatomic) CGFloat top;

/**
 控件底部
 */
@property (nonatomic) CGFloat bottom;

/**
 控件左边
 */
@property (nonatomic) CGFloat left;

/**
 控件右边
 */
@property (nonatomic) CGFloat right;

/**
 控件中心点X
 */
@property (nonatomic) CGFloat centerX;

/**
 控件中心点Y
 */
@property (nonatomic) CGFloat centerY;

/**
 控件左下
 */
@property(readonly) CGPoint BottomLeft ;

/**
 控件右下
 */
@property(readonly) CGPoint BottomRight ;

/**
 控件左上
 */
@property(readonly) CGPoint TopLeft ;
/**
 控件右上
 */
@property(readonly) CGPoint TopRight ;

/**
 屏幕中心点X
 */
@property (nonatomic, readonly) CGFloat middleX;

/**
 屏幕中心点Y
 */
@property (nonatomic, readonly) CGFloat middleY;

/**
 屏幕中心点
 */
@property (nonatomic, readonly) CGPoint middlePoint;

使用方法

所有继承UIView的控件都可以直接使用,参考代码如下。

//self.view的中心点的X
self.view.centerX

控件圆角设置

/**
 设置上边圆角
 */
- (void)setCornerOnTop:(CGFloat) conner;

/**
 设置下边圆角
 */
- (void)setCornerOnBottom:(CGFloat) conner;

/**
 设置左边圆角
 */
- (void)setCornerOnLeft:(CGFloat) conner;

/**
 设置右边圆角
 */
- (void)setCornerOnRight:(CGFloat) conner;

/**
 设置左上圆角
 */
- (void)setCornerOnTopLeft:(CGFloat) conner;

/**
 设置右上圆角
 */
- (void)setCornerOnTopRight:(CGFloat) conner;

/**
 设置左下圆角
 */
- (void)setCornerOnBottomLeft:(CGFloat) conner;

/**
 设置右下圆角
 */
- (void)setCornerOnBottomRight:(CGFloat) conner;

/**
 设置所有圆角
 */
- (void)setAllCorner:(CGFloat) conner;

分类地址

https://github.com/JmoVxia/UIView-SetRect

相关文章

  • 代码适配常用分类

    前言 很多时候我们喜欢使用代码直接做适配,但是很多原生的属性写起来非常浪费时间,于是写了一个常用属性分类。 主要属...

  • iOS 纯代码界面适配UIView扩展类

    下方代码为UIView的扩展分类,在纯代码界面适配中可以直接使用UIView控件的x,y,width,height...

  • JDK源码中的设计模式

    一、结构性模式: 1、适配器模式: 常用于将一个新接口适配旧接口 在我们业务代码中经常有新旧接口适配需求,可以采用...

  • Python学习笔记7—正则表达式之二

    字符分类 常用字符分类的缩写代码: \d--------------0到9的任何数字 \D------------...

  • she

    1.适配的分类 系统适配 屏幕适配 1.1屏幕适配历史 1.1.1autoresizing 去掉auto layo...

  • iOS UIViewController 生命周期 APPDe

    UIViewController APPDelegate 干货代码 我的一个纯代码的基础框架有各种常用的分类封装入手即用

  • 版本适配

    屏幕适配 代码适配 Masonry UIView+AutoLayout 可视化适配 autoLayout 系统适配...

  • iOS开发文档

    1.**关于适配** 1.代码适配:引用第三方库“SDAutoLayout”以及“Masonry”进行代码适配. ...

  • C#列出所有物理网络适配器的代码

    把写代码过程中常用的一些代码片段备份一次,下面代码是关于C#列出所有物理网络适配器的代码,应该对大家有用。 usi...

  • iOS常用分类方法

    在工作中总结了一些开发中常用到的分类,使用这些分类能使开发效率更高,让代码变得更简洁,减少了很多不必要的代码量,直...

网友评论

    本文标题:代码适配常用分类

    本文链接:https://www.haomeiwen.com/subject/qhqeuttx.html