BBALayout.h
3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// BBALayout.h
//
// Created by xmfeng on 14-10-14.
// Copyright (c) 2014年 xmfeng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface BBALayout : NSObject
@end
#pragma mark - 基于iPhone6Plus(414x736)标注
#define SX(v) ([[BBALayout layout_414x736] screenX:(v)])
#define SY(v) ([[BBALayout layout_414x736] screenY:(v)])
#define SV(v) ([[BBALayout layout_414x736] screen:(v)])
#define SFont(v) ([UIFont systemFontOfSize:SV(v)])
@interface BBALayout (Mark)
+ (instancetype)layout_414x736; // iPhone6Plus竖屏,此时.screenWidth/.screenHeight等只考虑竖屏情况
+ (instancetype)layout_736x414; // iPhone6Plus横屏,此时.screenWidth/.screenHeight等只考虑横屏情况
+ (instancetype)layout_414x736_736x414; // iPhone6Plus竖屏+横屏,此时.screenWidth/.screenHeight会根据屏幕状况进行切换
@property(nonatomic, assign, readonly) CGFloat screenWidth;
@property(nonatomic, assign, readonly) CGFloat screenHeight;
@property(nonatomic, assign, readonly) CGFloat screenScale;
@property(nonatomic, assign, readonly) CGFloat screenScaleX;
@property(nonatomic, assign, readonly) CGFloat screenScaleY;
- (CGFloat)screen:(CGFloat)v;
- (CGFloat)screenX:(CGFloat)x;
- (CGFloat)screenY:(CGFloat)y;
@end
#pragma mark utils
#define BBARectWidth(width) CGRectMake(0.0f, 0.0f, (width), 0.0f)
#define BBARectHeight(height) CGRectMake(0.0f, 0.0f, 0.0f, (height))
#define BBARectSize(width, height) CGRectMake(0.0f, 0.0f, (width), (height))
#define BBARectCenter(rect) CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect))
#pragma mark BBALayoutAlignment
#define BBALayoutAlignmentNone 0.0f
#define BBALayoutAlignmentLeft 0.0f
#define BBALayoutAlignmentRight 1.0f
#define BBALayoutAlignmentTop 0.0f
#define BBALayoutAlignmentBottom 1.0f
#define BBALayoutAlignmentCenter 0.5f
#define BBALayoutAlignmentMake(value) (value)
typedef CGFloat BBALayoutAlignment;
#pragma mark BBALayout
/*
* simple UIView
* @list for subviews
* @frame for frame, but can only edit origin with-no-rotation
*/
@protocol BBALayoutUnion
@optional
- (CGRect)frame;
- (void)setFrame:(CGRect)frame;
- (UIView *)superview;
@end
/*
* BBALayout
* layout [UIView or layouted-UIView] horizontally or vertically
* - NSNumber :indicate static offset
* - space :indicate <-->
* - UIView
* - layouted-UIView :returned-value of layout
*
* > only-layout, no @addSubview called, you should do outside;
* > Donot-Support-TransformScaled-Subview
*/
@interface BBALayout (LayoutSubviews)
// utils
// union[view.frame-viewed-by-viewer]
+ (CGRect)convertFrame:(NSArray *)views toView:(UIView *)viewer;
// consts
+ (id<BBALayoutUnion>)space;
// layout-horizontally for @viewer with a preffered min @frame and @align vertically
+ (id<BBALayoutUnion>)horizontal:(NSArray *)list
on:(UIView *)viewer
frame:(CGRect)frame
alignment:(BBALayoutAlignment)align;
// layout-vertically for @viewer with a preffered min @frame and @align horizontally
+ (id<BBALayoutUnion>)vertical:(NSArray *)list
on:(UIView *)viewer
frame:(CGRect)frame
alignment:(BBALayoutAlignment)align;
// layout-utils
+ (id<BBALayoutUnion>)horizontal:(NSArray *)list;
+ (id<BBALayoutUnion>)horizontal:(NSArray *)list width:(CGFloat)width;
+ (id<BBALayoutUnion>)vertical:(NSArray *)list;
+ (id<BBALayoutUnion>)vertical:(NSArray *)list height:(CGFloat)height;
+ (id<BBALayoutUnion>)ZOrder:(NSArray *)list;
// layout-view
+ (UIView *)horizontalView:(NSArray *)list;
+ (UIView *)horizontalView:(NSArray *)list width:(CGFloat)width;
+ (UIView *)verticalView:(NSArray *)list;
+ (UIView *)verticalView:(NSArray *)list height:(CGFloat)height;
@end