@aks-dev/easyui 1.0.32 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1812 @@
1
+ //
2
+ // UIView+SDAutoLayout.m
3
+ //
4
+ // Created by gsd on 15/10/6.
5
+ // Copyright (c) 2015年 gsd. All rights reserved.
6
+ //
7
+
8
+ /*
9
+
10
+ *********************************************************************************
11
+ * *
12
+ * 在您使用此自动布局库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 *
13
+ * 帮您解决问题。 *
14
+ * QQ : 2689718696(gsdios) *
15
+ * Email : gsdios@126.com *
16
+ * GitHub: https://github.com/gsdios *
17
+ * 新浪微博:GSD_iOS *
18
+ * *
19
+ *********************************************************************************
20
+
21
+ */
22
+
23
+ #import "UIView+SDAutoLayout.h"
24
+ #import "UITableView+SDAutoTableViewCellHeight.h"
25
+
26
+ #import <objc/runtime.h>
27
+
28
+ @interface SDAutoLayoutModel ()
29
+
30
+ @property (nonatomic, strong) SDAutoLayoutModelItem *width;
31
+ @property (nonatomic, strong) SDAutoLayoutModelItem *height;
32
+ @property (nonatomic, strong) SDAutoLayoutModelItem *left;
33
+ @property (nonatomic, strong) SDAutoLayoutModelItem *top;
34
+ @property (nonatomic, strong) SDAutoLayoutModelItem *right;
35
+ @property (nonatomic, strong) SDAutoLayoutModelItem *bottom;
36
+ @property (nonatomic, strong) NSNumber *centerX;
37
+ @property (nonatomic, strong) NSNumber *centerY;
38
+
39
+ @property (nonatomic, strong) NSNumber *maxWidth;
40
+ @property (nonatomic, strong) NSNumber *maxHeight;
41
+ @property (nonatomic, strong) NSNumber *minWidth;
42
+ @property (nonatomic, strong) NSNumber *minHeight;
43
+
44
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_width;
45
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_height;
46
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_left;
47
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_top;
48
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_right;
49
+ @property (nonatomic, strong) SDAutoLayoutModelItem *ratio_bottom;
50
+
51
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalLeft;
52
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalRight;
53
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalTop;
54
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalBottom;
55
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalCenterX;
56
+ @property (nonatomic, strong) SDAutoLayoutModelItem *equalCenterY;
57
+
58
+ @property (nonatomic, strong) SDAutoLayoutModelItem *widthEqualHeight;
59
+ @property (nonatomic, strong) SDAutoLayoutModelItem *heightEqualWidth;
60
+
61
+ @property (nonatomic, strong) SDAutoLayoutModelItem *lastModelItem;
62
+
63
+ @end
64
+
65
+ @implementation SDAutoLayoutModel
66
+
67
+ @synthesize leftSpaceToView = _leftSpaceToView;
68
+ @synthesize rightSpaceToView = _rightSpaceToView;
69
+ @synthesize topSpaceToView = _topSpaceToView;
70
+ @synthesize bottomSpaceToView = _bottomSpaceToView;
71
+ @synthesize widthIs = _widthIs;
72
+ @synthesize heightIs = _heightIs;
73
+ @synthesize widthRatioToView = _widthRatioToView;
74
+ @synthesize heightRatioToView = _heightRatioToView;
75
+ @synthesize leftEqualToView = _leftEqualToView;
76
+ @synthesize rightEqualToView = _rightEqualToView;
77
+ @synthesize topEqualToView = _topEqualToView;
78
+ @synthesize bottomEqualToView = _bottomEqualToView;
79
+ @synthesize centerXEqualToView = _centerXEqualToView;
80
+ @synthesize centerYEqualToView = _centerYEqualToView;
81
+ @synthesize xIs = _xIs;
82
+ @synthesize yIs = _yIs;
83
+ @synthesize centerXIs = _centerXIs;
84
+ @synthesize centerYIs = _centerYIs;
85
+ @synthesize autoHeightRatio = _autoHeightRatio;
86
+ @synthesize autoWidthRatio = _autoWidthRatio;
87
+ @synthesize spaceToSuperView = _spaceToSuperView;
88
+ @synthesize maxWidthIs = _maxWidthIs;
89
+ @synthesize maxHeightIs = _maxHeightIs;
90
+ @synthesize minWidthIs = _minWidthIs;
91
+ @synthesize minHeightIs = _minHeightIs;
92
+ @synthesize widthEqualToHeight = _widthEqualToHeight;
93
+ @synthesize heightEqualToWidth = _heightEqualToWidth;
94
+ @synthesize offset = _offset;
95
+
96
+
97
+ - (MarginToView)leftSpaceToView
98
+ {
99
+ if (!_leftSpaceToView) {
100
+ _leftSpaceToView = [self marginToViewblockWithKey:@"left"];
101
+ }
102
+ return _leftSpaceToView;
103
+ }
104
+
105
+ - (MarginToView)rightSpaceToView
106
+ {
107
+ if (!_rightSpaceToView) {
108
+ _rightSpaceToView = [self marginToViewblockWithKey:@"right"];
109
+ }
110
+ return _rightSpaceToView;
111
+ }
112
+
113
+ - (MarginToView)topSpaceToView
114
+ {
115
+ if (!_topSpaceToView) {
116
+ _topSpaceToView = [self marginToViewblockWithKey:@"top"];
117
+ }
118
+ return _topSpaceToView;
119
+ }
120
+
121
+ - (MarginToView)bottomSpaceToView
122
+ {
123
+ if (!_bottomSpaceToView) {
124
+ _bottomSpaceToView = [self marginToViewblockWithKey:@"bottom"];
125
+ }
126
+ return _bottomSpaceToView;
127
+ }
128
+
129
+ - (MarginToView)marginToViewblockWithKey:(NSString *)key
130
+ {
131
+ __weak typeof(self) weakSelf = self;
132
+ return ^(id viewOrViewsArray, CGFloat value) {
133
+ SDAutoLayoutModelItem *item = [SDAutoLayoutModelItem new];
134
+ item.value = @(value);
135
+ if ([viewOrViewsArray isKindOfClass:[UIView class]]) {
136
+ item.refView = viewOrViewsArray;
137
+ } else if ([viewOrViewsArray isKindOfClass:[NSArray class]]) {
138
+ item.refViewsArray = [viewOrViewsArray copy];
139
+ }
140
+ [weakSelf setValue:item forKey:key];
141
+ return weakSelf;
142
+ };
143
+ }
144
+
145
+ - (WidthHeight)widthIs
146
+ {
147
+ if (!_widthIs) {
148
+ __weak typeof(self) weakSelf = self;
149
+ _widthIs = ^(CGFloat value) {
150
+ weakSelf.needsAutoResizeView.fixedWidth = @(value);
151
+ SDAutoLayoutModelItem *widthItem = [SDAutoLayoutModelItem new];
152
+ widthItem.value = @(value);
153
+ weakSelf.width = widthItem;
154
+ return weakSelf;
155
+ };
156
+ }
157
+ return _widthIs;
158
+ }
159
+
160
+ - (WidthHeight)heightIs
161
+ {
162
+ if (!_heightIs) {
163
+ __weak typeof(self) weakSelf = self;
164
+ _heightIs = ^(CGFloat value) {
165
+ weakSelf.needsAutoResizeView.fixedHeight = @(value);
166
+ SDAutoLayoutModelItem *heightItem = [SDAutoLayoutModelItem new];
167
+ heightItem.value = @(value);
168
+ weakSelf.height = heightItem;
169
+ return weakSelf;
170
+ };
171
+ }
172
+ return _heightIs;
173
+ }
174
+
175
+ - (WidthHeightEqualToView)widthRatioToView
176
+ {
177
+ if (!_widthRatioToView) {
178
+ __weak typeof(self) weakSelf = self;
179
+ _widthRatioToView = ^(UIView *view, CGFloat value) {
180
+ weakSelf.ratio_width = [SDAutoLayoutModelItem new];
181
+ weakSelf.ratio_width.value = @(value);
182
+ weakSelf.ratio_width.refView = view;
183
+ return weakSelf;
184
+ };
185
+ }
186
+ return _widthRatioToView;
187
+ }
188
+
189
+ - (WidthHeightEqualToView)heightRatioToView
190
+ {
191
+ if (!_heightRatioToView) {
192
+ __weak typeof(self) weakSelf = self;
193
+ _heightRatioToView = ^(UIView *view, CGFloat value) {
194
+ weakSelf.ratio_height = [SDAutoLayoutModelItem new];
195
+ weakSelf.ratio_height.refView = view;
196
+ weakSelf.ratio_height.value = @(value);
197
+ return weakSelf;
198
+ };
199
+ }
200
+ return _heightRatioToView;
201
+ }
202
+
203
+ - (WidthHeight)maxWidthIs
204
+ {
205
+ if (!_maxWidthIs) {
206
+ _maxWidthIs = [self limitingWidthHeightWithKey:@"maxWidth"];
207
+ }
208
+ return _maxWidthIs;
209
+ }
210
+
211
+ - (WidthHeight)maxHeightIs
212
+ {
213
+ if (!_maxHeightIs) {
214
+ _maxHeightIs = [self limitingWidthHeightWithKey:@"maxHeight"];
215
+ }
216
+ return _maxHeightIs;
217
+ }
218
+
219
+ - (WidthHeight)minWidthIs
220
+ {
221
+ if (!_minWidthIs) {
222
+ _minWidthIs = [self limitingWidthHeightWithKey:@"minWidth"];
223
+ }
224
+ return _minWidthIs;
225
+ }
226
+
227
+ - (WidthHeight)minHeightIs
228
+ {
229
+ if (!_minHeightIs) {
230
+ _minHeightIs = [self limitingWidthHeightWithKey:@"minHeight"];
231
+ }
232
+ return _minHeightIs;
233
+ }
234
+
235
+
236
+ - (WidthHeight)limitingWidthHeightWithKey:(NSString *)key
237
+ {
238
+ __weak typeof(self) weakSelf = self;
239
+
240
+ return ^(CGFloat value) {
241
+ [weakSelf setValue:@(value) forKey:key];
242
+
243
+ return weakSelf;
244
+ };
245
+ }
246
+
247
+
248
+ - (MarginEqualToView)marginEqualToViewBlockWithKey:(NSString *)key
249
+ {
250
+ __weak typeof(self) weakSelf = self;
251
+
252
+ return ^(UIView *view) {
253
+ SDAutoLayoutModelItem *item = [SDAutoLayoutModelItem new];
254
+ item.refView = view;
255
+ [weakSelf setValue:item forKey:key];
256
+ weakSelf.lastModelItem = item;
257
+ if ([view isKindOfClass:NSClassFromString(@"UITableViewCellContentView")] && ([key isEqualToString:@"equalCenterY"] || [key isEqualToString:@"equalBottom"])) {
258
+ view.shouldReadjustFrameBeforeStoreCache = YES;
259
+ }
260
+ return weakSelf;
261
+ };
262
+ }
263
+
264
+ - (MarginEqualToView)leftEqualToView
265
+ {
266
+ if (!_leftEqualToView) {
267
+ _leftEqualToView = [self marginEqualToViewBlockWithKey:@"equalLeft"];
268
+ }
269
+ return _leftEqualToView;
270
+ }
271
+
272
+ - (MarginEqualToView)rightEqualToView
273
+ {
274
+ if (!_rightEqualToView) {
275
+ _rightEqualToView = [self marginEqualToViewBlockWithKey:@"equalRight"];
276
+ }
277
+ return _rightEqualToView;
278
+ }
279
+
280
+ - (MarginEqualToView)topEqualToView
281
+ {
282
+ if (!_topEqualToView) {
283
+ _topEqualToView = [self marginEqualToViewBlockWithKey:@"equalTop"];
284
+ }
285
+ return _topEqualToView;
286
+ }
287
+
288
+ - (MarginEqualToView)bottomEqualToView
289
+ {
290
+ if (!_bottomEqualToView) {
291
+ _bottomEqualToView = [self marginEqualToViewBlockWithKey:@"equalBottom"];
292
+ }
293
+ return _bottomEqualToView;
294
+ }
295
+
296
+ - (MarginEqualToView)centerXEqualToView
297
+ {
298
+ if (!_centerXEqualToView) {
299
+ _centerXEqualToView = [self marginEqualToViewBlockWithKey:@"equalCenterX"];
300
+ }
301
+ return _centerXEqualToView;
302
+ }
303
+
304
+ - (MarginEqualToView)centerYEqualToView
305
+ {
306
+ if (!_centerYEqualToView) {
307
+ _centerYEqualToView = [self marginEqualToViewBlockWithKey:@"equalCenterY"];
308
+ }
309
+ return _centerYEqualToView;
310
+ }
311
+
312
+
313
+ - (Margin)marginBlockWithKey:(NSString *)key
314
+ {
315
+ __weak typeof(self) weakSelf = self;
316
+
317
+ return ^(CGFloat value) {
318
+
319
+ if ([key isEqualToString:@"x"]) {
320
+ weakSelf.needsAutoResizeView.left_sd = value;
321
+ } else if ([key isEqualToString:@"y"]) {
322
+ weakSelf.needsAutoResizeView.top_sd = value;
323
+ } else if ([key isEqualToString:@"centerX"]) {
324
+ weakSelf.centerX = @(value);
325
+ } else if ([key isEqualToString:@"centerY"]) {
326
+ weakSelf.centerY = @(value);
327
+ }
328
+
329
+ return weakSelf;
330
+ };
331
+ }
332
+
333
+ - (Margin)xIs
334
+ {
335
+ if (!_xIs) {
336
+ _xIs = [self marginBlockWithKey:@"x"];
337
+ }
338
+ return _xIs;
339
+ }
340
+
341
+ - (Margin)yIs
342
+ {
343
+ if (!_yIs) {
344
+ _yIs = [self marginBlockWithKey:@"y"];
345
+ }
346
+ return _yIs;
347
+ }
348
+
349
+ - (Margin)centerXIs
350
+ {
351
+ if (!_centerXIs) {
352
+ _centerXIs = [self marginBlockWithKey:@"centerX"];
353
+ }
354
+ return _centerXIs;
355
+ }
356
+
357
+ - (Margin)centerYIs
358
+ {
359
+ if (!_centerYIs) {
360
+ _centerYIs = [self marginBlockWithKey:@"centerY"];
361
+ }
362
+ return _centerYIs;
363
+ }
364
+
365
+ - (AutoHeightWidth)autoHeightRatio
366
+ {
367
+ __weak typeof(self) weakSelf = self;
368
+
369
+ if (!_autoHeightRatio) {
370
+ _autoHeightRatio = ^(CGFloat ratioaValue) {
371
+ weakSelf.needsAutoResizeView.autoHeightRatioValue = @(ratioaValue);
372
+ return weakSelf;
373
+ };
374
+ }
375
+ return _autoHeightRatio;
376
+ }
377
+
378
+ - (AutoHeightWidth)autoWidthRatio
379
+ {
380
+ __weak typeof(self) weakSelf = self;
381
+
382
+ if (!_autoWidthRatio) {
383
+ _autoWidthRatio = ^(CGFloat ratioaValue) {
384
+ weakSelf.needsAutoResizeView.autoWidthRatioValue = @(ratioaValue);
385
+ return weakSelf;
386
+ };
387
+ }
388
+ return _autoWidthRatio;
389
+ }
390
+
391
+ - (SpaceToSuperView)spaceToSuperView
392
+ {
393
+ __weak typeof(self) weakSelf = self;
394
+
395
+ if (!_spaceToSuperView) {
396
+ _spaceToSuperView = ^(UIEdgeInsets insets) {
397
+ UIView *superView = weakSelf.needsAutoResizeView.superview;
398
+ if (superView) {
399
+ weakSelf.needsAutoResizeView.sd_layout
400
+ .leftSpaceToView(superView, insets.left)
401
+ .topSpaceToView(superView, insets.top)
402
+ .rightSpaceToView(superView, insets.right)
403
+ .bottomSpaceToView(superView, insets.bottom);
404
+ }
405
+ };
406
+ }
407
+ return _spaceToSuperView;
408
+ }
409
+
410
+ - (SameWidthHeight)widthEqualToHeight
411
+ {
412
+ __weak typeof(self) weakSelf = self;
413
+
414
+ if (!_widthEqualToHeight) {
415
+ _widthEqualToHeight = ^() {
416
+ weakSelf.widthEqualHeight = [SDAutoLayoutModelItem new];
417
+ weakSelf.lastModelItem = weakSelf.widthEqualHeight;
418
+ // 主动触发一次赋值操作
419
+ weakSelf.needsAutoResizeView.height_sd = weakSelf.needsAutoResizeView.height_sd;
420
+ return weakSelf;
421
+ };
422
+ }
423
+ return _widthEqualToHeight;
424
+ }
425
+
426
+ - (SameWidthHeight)heightEqualToWidth
427
+ {
428
+ __weak typeof(self) weakSelf = self;
429
+
430
+ if (!_heightEqualToWidth) {
431
+ _heightEqualToWidth = ^() {
432
+ weakSelf.heightEqualWidth = [SDAutoLayoutModelItem new];
433
+ weakSelf.lastModelItem = weakSelf.heightEqualWidth;
434
+ // 主动触发一次赋值操作
435
+ weakSelf.needsAutoResizeView.width_sd = weakSelf.needsAutoResizeView.width_sd;
436
+ return weakSelf;
437
+ };
438
+ }
439
+ return _heightEqualToWidth;
440
+ }
441
+
442
+ - (SDAutoLayoutModel *(^)(CGFloat))offset
443
+ {
444
+ __weak typeof(self) weakSelf = self;
445
+ if (!_offset) {
446
+ _offset = ^(CGFloat offset) {
447
+ weakSelf.lastModelItem.offset = offset;
448
+ return weakSelf;
449
+ };
450
+ }
451
+ return _offset;
452
+ }
453
+
454
+ @end
455
+
456
+
457
+ @implementation UIView (SDAutoHeightWidth)
458
+
459
+ - (SDUIViewCategoryManager *)sd_categoryManager
460
+ {
461
+ SDUIViewCategoryManager *manager = objc_getAssociatedObject(self, _cmd);
462
+ if (!manager) {
463
+ objc_setAssociatedObject(self, _cmd, [SDUIViewCategoryManager new], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
464
+ }
465
+ return objc_getAssociatedObject(self, _cmd);
466
+ }
467
+
468
+ - (void)setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin
469
+ {
470
+ if (!bottomView) return;
471
+
472
+ [self setupAutoHeightWithBottomViewsArray:@[bottomView] bottomMargin:bottomMargin];
473
+ }
474
+
475
+ - (void)setupAutoWidthWithRightView:(UIView *)rightView rightMargin:(CGFloat)rightMargin
476
+ {
477
+ if (!rightView) return;
478
+
479
+ self.sd_rightViewsArray = @[rightView];
480
+ self.sd_rightViewRightMargin = rightMargin;
481
+ }
482
+
483
+ - (void)setupAutoHeightWithBottomViewsArray:(NSArray *)bottomViewsArray bottomMargin:(CGFloat)bottomMargin
484
+ {
485
+ if (!bottomViewsArray) return;
486
+
487
+ // 清空之前的view
488
+ [self.sd_bottomViewsArray removeAllObjects];
489
+ [self.sd_bottomViewsArray addObjectsFromArray:bottomViewsArray];
490
+ self.sd_bottomViewBottomMargin = bottomMargin;
491
+ }
492
+
493
+ - (void)clearAutoHeigtSettings
494
+ {
495
+ [self.sd_bottomViewsArray removeAllObjects];
496
+ }
497
+
498
+ - (void)clearAutoWidthSettings
499
+ {
500
+ self.sd_rightViewsArray = nil;
501
+ }
502
+
503
+ - (void)updateLayout
504
+ {
505
+ [self.superview layoutSubviews];
506
+ }
507
+
508
+ - (void)updateLayoutWithCellContentView:(UIView *)cellContentView
509
+ {
510
+ if (cellContentView.sd_indexPath) {
511
+ [cellContentView sd_clearSubviewsAutoLayoutFrameCaches];
512
+ }
513
+ [self updateLayout];
514
+ }
515
+
516
+ - (CGFloat)autoHeight
517
+ {
518
+ return [objc_getAssociatedObject(self, _cmd) floatValue];
519
+ }
520
+
521
+ - (void)setAutoHeight:(CGFloat)autoHeight
522
+ {
523
+ objc_setAssociatedObject(self, @selector(autoHeight), @(autoHeight), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
524
+ }
525
+
526
+ - (NSMutableArray *)sd_bottomViewsArray
527
+ {
528
+ NSMutableArray *array = objc_getAssociatedObject(self, _cmd);
529
+ if (!array) {
530
+ objc_setAssociatedObject(self, _cmd, [NSMutableArray new], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
531
+ }
532
+ return objc_getAssociatedObject(self, _cmd);
533
+ }
534
+
535
+ - (NSArray *)sd_rightViewsArray
536
+ {
537
+ return [[self sd_categoryManager] rightViewsArray];
538
+ }
539
+
540
+ - (void)setSd_rightViewsArray:(NSArray *)sd_rightViewsArray
541
+ {
542
+ [[self sd_categoryManager] setRightViewsArray:sd_rightViewsArray];
543
+ }
544
+
545
+ - (CGFloat)sd_bottomViewBottomMargin
546
+ {
547
+ return [objc_getAssociatedObject(self, _cmd) floatValue];
548
+ }
549
+
550
+ - (void)setSd_bottomViewBottomMargin:(CGFloat)sd_bottomViewBottomMargin
551
+ {
552
+ objc_setAssociatedObject(self, @selector(sd_bottomViewBottomMargin), @(sd_bottomViewBottomMargin), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
553
+ }
554
+
555
+ - (void)setSd_rightViewRightMargin:(CGFloat)sd_rightViewRightMargin
556
+ {
557
+ [[self sd_categoryManager] setRightViewRightMargin:sd_rightViewRightMargin];
558
+ }
559
+
560
+ - (CGFloat)sd_rightViewRightMargin
561
+ {
562
+ return [[self sd_categoryManager] rightViewRightMargin];
563
+ }
564
+
565
+ @end
566
+
567
+ @implementation UIView (SDLayoutExtention)
568
+
569
+ - (void (^)(CGRect))didFinishAutoLayoutBlock
570
+ {
571
+ return objc_getAssociatedObject(self, _cmd);
572
+ }
573
+
574
+ - (void)setDidFinishAutoLayoutBlock:(void (^)(CGRect))didFinishAutoLayoutBlock
575
+ {
576
+ objc_setAssociatedObject(self, @selector(didFinishAutoLayoutBlock), didFinishAutoLayoutBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
577
+ }
578
+
579
+ - (NSNumber *)sd_cornerRadius
580
+ {
581
+ return objc_getAssociatedObject(self, _cmd);
582
+ }
583
+
584
+ - (void)setSd_cornerRadius:(NSNumber *)sd_cornerRadius
585
+ {
586
+ objc_setAssociatedObject(self, @selector(sd_cornerRadius), sd_cornerRadius, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
587
+ }
588
+
589
+
590
+ - (NSNumber *)sd_cornerRadiusFromWidthRatio
591
+ {
592
+ return objc_getAssociatedObject(self, _cmd);
593
+ }
594
+
595
+ - (void)setSd_cornerRadiusFromWidthRatio:(NSNumber *)sd_cornerRadiusFromWidthRatio
596
+ {
597
+ objc_setAssociatedObject(self, @selector(sd_cornerRadiusFromWidthRatio), sd_cornerRadiusFromWidthRatio, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
598
+ }
599
+
600
+
601
+ - (NSNumber *)sd_cornerRadiusFromHeightRatio
602
+ {
603
+ return objc_getAssociatedObject(self, _cmd);
604
+ }
605
+
606
+ - (void)setSd_cornerRadiusFromHeightRatio:(NSNumber *)sd_cornerRadiusFromHeightRatio
607
+ {
608
+ objc_setAssociatedObject(self, @selector(sd_cornerRadiusFromHeightRatio), sd_cornerRadiusFromHeightRatio, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
609
+ }
610
+
611
+ - (NSArray *)sd_equalWidthSubviews
612
+ {
613
+ return objc_getAssociatedObject(self, _cmd);
614
+ }
615
+
616
+ - (void)setSd_equalWidthSubviews:(NSArray *)sd_equalWidthSubviews
617
+ {
618
+ objc_setAssociatedObject(self, @selector(sd_equalWidthSubviews), sd_equalWidthSubviews, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
619
+ }
620
+
621
+ - (void)sd_addSubviews:(NSArray *)subviews
622
+ {
623
+ [subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
624
+ if ([view isKindOfClass:[UIView class]]) {
625
+ [self addSubview:view];
626
+ }
627
+ }];
628
+ }
629
+
630
+ @end
631
+
632
+ @implementation UIView (SDAutoFlowItems)
633
+
634
+ - (void)setupAutoWidthFlowItems:(NSArray *)viewsArray withPerRowItemsCount:(NSInteger)perRowItemsCount verticalMargin:(CGFloat)verticalMargin horizontalMargin:(CGFloat)horizontalMagin verticalEdgeInset:(CGFloat)vInset horizontalEdgeInset:(CGFloat)hInset
635
+ {
636
+ self.sd_categoryManager.flowItems = viewsArray;
637
+ self.sd_categoryManager.perRowItemsCount = perRowItemsCount;
638
+ self.sd_categoryManager.verticalMargin = verticalMargin;
639
+ self.sd_categoryManager.horizontalMargin = horizontalMagin;
640
+ self.verticalEdgeInset = vInset;
641
+ self.horizontalEdgeInset = hInset;
642
+
643
+ self.sd_categoryManager.lastWidth = 0;
644
+
645
+ if (viewsArray.count) {
646
+ [self setupAutoHeightWithBottomView:viewsArray.lastObject bottomMargin:vInset];
647
+ } else {
648
+ [self clearAutoHeigtSettings];
649
+ }
650
+ }
651
+
652
+ - (void)clearAutoWidthFlowItemsSettings
653
+ {
654
+ [self setupAutoWidthFlowItems:nil withPerRowItemsCount:0 verticalMargin:0 horizontalMargin:0 verticalEdgeInset:0 horizontalEdgeInset:0];
655
+ }
656
+
657
+ - (void)setupAutoMarginFlowItems:(NSArray *)viewsArray withPerRowItemsCount:(NSInteger)perRowItemsCount itemWidth:(CGFloat)itemWidth verticalMargin:(CGFloat)verticalMargin verticalEdgeInset:(CGFloat)vInset horizontalEdgeInset:(CGFloat)hInset
658
+ {
659
+ self.sd_categoryManager.shouldShowAsAutoMarginViews = YES;
660
+ self.sd_categoryManager.flowItemWidth = itemWidth;
661
+ [self setupAutoWidthFlowItems:viewsArray withPerRowItemsCount:perRowItemsCount verticalMargin:verticalMargin horizontalMargin:0 verticalEdgeInset:vInset horizontalEdgeInset:hInset];
662
+ }
663
+
664
+ - (void)clearAutoMarginFlowItemsSettings
665
+ {
666
+ [self setupAutoMarginFlowItems:nil withPerRowItemsCount:0 itemWidth:0 verticalMargin:0 verticalEdgeInset:0 horizontalEdgeInset:0];
667
+ }
668
+
669
+ - (void)setHorizontalEdgeInset:(CGFloat)horizontalEdgeInset
670
+ {
671
+ self.sd_categoryManager.horizontalEdgeInset = horizontalEdgeInset;
672
+ }
673
+
674
+ - (CGFloat)horizontalEdgeInset
675
+ {
676
+ return self.sd_categoryManager.horizontalEdgeInset;
677
+ }
678
+
679
+ - (void)setVerticalEdgeInset:(CGFloat)verticalEdgeInset
680
+ {
681
+ self.sd_categoryManager.verticalEdgeInset = verticalEdgeInset;
682
+ }
683
+
684
+ - (CGFloat)verticalEdgeInset
685
+ {
686
+ return self.sd_categoryManager.verticalEdgeInset;
687
+ }
688
+
689
+ @end
690
+
691
+ @implementation UIScrollView (SDAutoContentSize)
692
+
693
+ - (void)setupAutoContentSizeWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin
694
+ {
695
+ [self setupAutoHeightWithBottomView:bottomView bottomMargin:bottomMargin];
696
+ }
697
+
698
+ - (void)setupAutoContentSizeWithRightView:(UIView *)rightView rightMargin:(CGFloat)rightMargin
699
+ {
700
+ if (!rightView) return;
701
+
702
+ self.sd_rightViewsArray = @[rightView];
703
+ self.sd_rightViewRightMargin = rightMargin;
704
+ }
705
+
706
+ @end
707
+
708
+ @implementation UILabel (SDLabelAutoResize)
709
+
710
+ + (void)load
711
+ {
712
+ static dispatch_once_t onceToken;
713
+ dispatch_once(&onceToken, ^{
714
+
715
+ NSArray *selStringsArray = @[@"setText:"];
716
+
717
+ [selStringsArray enumerateObjectsUsingBlock:^(NSString *selString, NSUInteger idx, BOOL *stop) {
718
+ NSString *mySelString = [@"sd_" stringByAppendingString:selString];
719
+
720
+ Method originalMethod = class_getInstanceMethod(self, NSSelectorFromString(selString));
721
+ Method myMethod = class_getInstanceMethod(self, NSSelectorFromString(mySelString));
722
+ method_exchangeImplementations(originalMethod, myMethod);
723
+ }];
724
+ });
725
+ }
726
+
727
+ - (void)sd_setText:(NSString *)text
728
+ {
729
+ // 如果程序崩溃在这行代码说明是你的label在执行“setText”方法时出了问题而不是在此自动布局库内部出现了问题,请检查你的“setText”方法
730
+ [self sd_setText:text];
731
+
732
+
733
+ if (self.sd_maxWidth) {
734
+ [self sizeToFit];
735
+ } else if (self.autoHeightRatioValue) {
736
+ self.size_sd = CGSizeZero;
737
+ }
738
+ }
739
+
740
+ - (BOOL)isAttributedContent
741
+ {
742
+ return [objc_getAssociatedObject(self, _cmd) boolValue];
743
+ }
744
+
745
+ - (void)setIsAttributedContent:(BOOL)isAttributedContent
746
+ {
747
+ objc_setAssociatedObject(self, @selector(isAttributedContent), @(isAttributedContent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
748
+ }
749
+
750
+ - (void)setSingleLineAutoResizeWithMaxWidth:(CGFloat)maxWidth
751
+ {
752
+ self.sd_maxWidth = @(maxWidth);
753
+ }
754
+
755
+ - (void)setMaxNumberOfLinesToShow:(NSInteger)lineCount
756
+ {
757
+ NSAssert(self.ownLayoutModel, @"请在布局完成之后再做此步设置!");
758
+ if (lineCount > 0) {
759
+ self.sd_layout.maxHeightIs(self.font.lineHeight * lineCount + 0.1);
760
+ } else {
761
+ self.sd_layout.maxHeightIs(MAXFLOAT);
762
+ }
763
+ }
764
+
765
+ @end
766
+
767
+ @implementation UIButton (SDExtention)
768
+
769
+ - (void)setupAutoSizeWithHorizontalPadding:(CGFloat)hPadding buttonHeight:(CGFloat)buttonHeight
770
+ {
771
+ self.fixedHeight = @(buttonHeight);
772
+
773
+ self.titleLabel.sd_layout
774
+ .leftSpaceToView(self, hPadding)
775
+ .topEqualToView(self)
776
+ .heightIs(buttonHeight);
777
+
778
+ [self.titleLabel setSingleLineAutoResizeWithMaxWidth:MAXFLOAT];
779
+ [self setupAutoWidthWithRightView:self.titleLabel rightMargin:hPadding];
780
+ }
781
+
782
+ @end
783
+
784
+
785
+ @implementation SDAutoLayoutModelItem
786
+
787
+ - (instancetype)init
788
+ {
789
+ if (self = [super init]) {
790
+ _offset = 0;
791
+ }
792
+ return self;
793
+ }
794
+
795
+ @end
796
+
797
+
798
+ @implementation UIView (SDAutoLayout)
799
+
800
+ + (void)load
801
+ {
802
+ static dispatch_once_t onceToken;
803
+ dispatch_once(&onceToken, ^{
804
+
805
+ NSArray *selStringsArray = @[@"layoutSubviews"];
806
+
807
+ [selStringsArray enumerateObjectsUsingBlock:^(NSString *selString, NSUInteger idx, BOOL *stop) {
808
+ NSString *mySelString = [@"sd_" stringByAppendingString:selString];
809
+
810
+ Method originalMethod = class_getInstanceMethod(self, NSSelectorFromString(selString));
811
+ Method myMethod = class_getInstanceMethod(self, NSSelectorFromString(mySelString));
812
+ method_exchangeImplementations(originalMethod, myMethod);
813
+ }];
814
+ });
815
+ }
816
+
817
+ #pragma mark - properties
818
+
819
+ - (NSMutableArray *)autoLayoutModelsArray
820
+ {
821
+ if (!objc_getAssociatedObject(self, _cmd)) {
822
+ objc_setAssociatedObject(self, _cmd, [NSMutableArray array], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
823
+ }
824
+ return objc_getAssociatedObject(self, _cmd);
825
+ }
826
+
827
+ - (NSNumber *)fixedWidth
828
+ {
829
+ return objc_getAssociatedObject(self, _cmd);
830
+ }
831
+
832
+ - (void)setFixedWidth:(NSNumber *)fixedWidth
833
+ {
834
+ if (fixedWidth) {
835
+ self.width_sd = [fixedWidth floatValue];
836
+ }
837
+ objc_setAssociatedObject(self, @selector(fixedWidth), fixedWidth, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
838
+ }
839
+
840
+ - (NSNumber *)fixedHeight
841
+ {
842
+ return objc_getAssociatedObject(self, _cmd);
843
+ }
844
+
845
+ - (void)setFixedHeight:(NSNumber *)fixedHeight
846
+ {
847
+ if (fixedHeight) {
848
+ self.height_sd = [fixedHeight floatValue];
849
+ }
850
+ objc_setAssociatedObject(self, @selector(fixedHeight), fixedHeight, OBJC_ASSOCIATION_RETAIN);
851
+ }
852
+
853
+ - (NSNumber *)autoHeightRatioValue
854
+ {
855
+ return objc_getAssociatedObject(self, _cmd);
856
+ }
857
+
858
+ - (void)setAutoHeightRatioValue:(NSNumber *)autoHeightRatioValue
859
+ {
860
+ objc_setAssociatedObject(self, @selector(autoHeightRatioValue), autoHeightRatioValue, OBJC_ASSOCIATION_RETAIN);
861
+ }
862
+
863
+ - (NSNumber *)autoWidthRatioValue
864
+ {
865
+ return objc_getAssociatedObject(self, _cmd);
866
+ }
867
+
868
+ - (void)setAutoWidthRatioValue:(NSNumber *)autoWidthRatioValue
869
+ {
870
+ objc_setAssociatedObject(self, @selector(autoWidthRatioValue), autoWidthRatioValue, OBJC_ASSOCIATION_RETAIN);
871
+ }
872
+
873
+ - (NSNumber *)sd_maxWidth
874
+ {
875
+ return objc_getAssociatedObject(self, _cmd);
876
+ }
877
+
878
+ - (void)setSd_maxWidth:(NSNumber *)sd_maxWidth
879
+ {
880
+ objc_setAssociatedObject(self, @selector(sd_maxWidth), sd_maxWidth, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
881
+ }
882
+
883
+ - (void)useCellFrameCacheWithIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableview
884
+ {
885
+ self.sd_indexPath = indexPath;
886
+ self.sd_tableView = tableview;
887
+ }
888
+
889
+ - (UITableView *)sd_tableView
890
+ {
891
+ return self.sd_categoryManager.sd_tableView;
892
+ }
893
+
894
+ - (void)setSd_tableView:(UITableView *)sd_tableView
895
+ {
896
+ if ([self isKindOfClass:[UITableViewCell class]]) {
897
+ [(UITableViewCell *)self contentView].sd_tableView = sd_tableView;
898
+ }
899
+ self.sd_categoryManager.sd_tableView = sd_tableView;
900
+ }
901
+
902
+ - (NSIndexPath *)sd_indexPath
903
+ {
904
+ return self.sd_categoryManager.sd_indexPath;
905
+ }
906
+
907
+ - (void)setSd_indexPath:(NSIndexPath *)sd_indexPath
908
+ {
909
+ if ([self isKindOfClass:[UITableViewCell class]]) {
910
+ [(UITableViewCell *)self contentView].sd_indexPath = sd_indexPath;
911
+ }
912
+ self.sd_categoryManager.sd_indexPath = sd_indexPath;
913
+ }
914
+
915
+ - (SDAutoLayoutModel *)ownLayoutModel
916
+ {
917
+ return objc_getAssociatedObject(self, _cmd);
918
+ }
919
+
920
+ - (void)setOwnLayoutModel:(SDAutoLayoutModel *)ownLayoutModel
921
+ {
922
+ objc_setAssociatedObject(self, @selector(ownLayoutModel), ownLayoutModel, OBJC_ASSOCIATION_RETAIN);
923
+ }
924
+
925
+ - (SDAutoLayoutModel *)sd_layout
926
+ {
927
+
928
+ #ifdef SDDebugWithAssert
929
+ /*
930
+ 卡在这里说明你的要自动布局的view在没有添加到父view的情况下就开始设置布局,你需要这样:
931
+ 1. UIView *view = [UIView new];
932
+ 2. [superView addSubview:view];
933
+ 3. view.sd_layout
934
+ .leftEqualToView()...
935
+ */
936
+ NSAssert(self.superview, @">>>>>>>>>在加入父view之后才可以做自动布局设置");
937
+
938
+ #endif
939
+
940
+ SDAutoLayoutModel *model = [self ownLayoutModel];
941
+ if (!model) {
942
+ model = [SDAutoLayoutModel new];
943
+ model.needsAutoResizeView = self;
944
+ [self setOwnLayoutModel:model];
945
+ [self.superview.autoLayoutModelsArray addObject:model];
946
+ }
947
+
948
+ return model;
949
+ }
950
+
951
+ - (SDAutoLayoutModel *)sd_resetLayout
952
+ {
953
+ /*
954
+ * 方案待定
955
+ [self sd_clearAutoLayoutSettings];
956
+ return [self sd_layout];
957
+ */
958
+
959
+ SDAutoLayoutModel *model = [self ownLayoutModel];
960
+ SDAutoLayoutModel *newModel = [SDAutoLayoutModel new];
961
+ newModel.needsAutoResizeView = self;
962
+ [self sd_clearViewFrameCache];
963
+ NSInteger index = 0;
964
+ if (model) {
965
+ index = [self.superview.autoLayoutModelsArray indexOfObject:model];
966
+ [self.superview.autoLayoutModelsArray replaceObjectAtIndex:index withObject:newModel];
967
+ } else {
968
+ [self.superview.autoLayoutModelsArray addObject:newModel];
969
+ }
970
+ [self setOwnLayoutModel:newModel];
971
+ [self sd_clearExtraAutoLayoutItems];
972
+ return newModel;
973
+ }
974
+
975
+ - (SDAutoLayoutModel *)sd_resetNewLayout
976
+ {
977
+ [self sd_clearAutoLayoutSettings];
978
+ [self sd_clearExtraAutoLayoutItems];
979
+ return [self sd_layout];
980
+ }
981
+
982
+ - (BOOL)sd_isClosingAutoLayout
983
+ {
984
+ return self.sd_categoryManager.sd_isClosingAutoLayout;
985
+ }
986
+
987
+ - (void)setSd_closeAutoLayout:(BOOL)sd_closeAutoLayout
988
+ {
989
+ self.sd_categoryManager.sd_closeAutoLayout = sd_closeAutoLayout;
990
+ }
991
+
992
+ - (void)removeFromSuperviewAndClearAutoLayoutSettings
993
+ {
994
+ [self sd_clearAutoLayoutSettings];
995
+ [self removeFromSuperview];
996
+ }
997
+
998
+ - (void)sd_clearAutoLayoutSettings
999
+ {
1000
+ SDAutoLayoutModel *model = [self ownLayoutModel];
1001
+ if (model) {
1002
+ [self.superview.autoLayoutModelsArray removeObject:model];
1003
+ [self setOwnLayoutModel:nil];
1004
+ }
1005
+ [self sd_clearExtraAutoLayoutItems];
1006
+ }
1007
+
1008
+ - (void)sd_clearExtraAutoLayoutItems
1009
+ {
1010
+ if (self.autoHeightRatioValue) {
1011
+ self.autoHeightRatioValue = nil;
1012
+ }
1013
+ self.fixedHeight = nil;
1014
+ self.fixedWidth = nil;
1015
+ }
1016
+
1017
+ - (void)sd_clearViewFrameCache
1018
+ {
1019
+ self.frame = CGRectZero;
1020
+ }
1021
+
1022
+ - (void)sd_clearSubviewsAutoLayoutFrameCaches
1023
+ {
1024
+ if (self.sd_tableView && self.sd_indexPath) {
1025
+ [self.sd_tableView.cellAutoHeightManager clearHeightCacheOfIndexPaths:@[self.sd_indexPath]];
1026
+ return;
1027
+ }
1028
+
1029
+ if (self.autoLayoutModelsArray.count == 0) return;
1030
+
1031
+ [self.autoLayoutModelsArray enumerateObjectsUsingBlock:^(SDAutoLayoutModel *model, NSUInteger idx, BOOL *stop) {
1032
+ model.needsAutoResizeView.frame = CGRectZero;
1033
+ }];
1034
+ }
1035
+
1036
+ - (void)sd_layoutSubviews
1037
+ {
1038
+ // 如果程序崩溃在这行代码说明是你的view在执行“layoutSubvies”方法时出了问题而不是在此自动布局库内部出现了问题,请检查你的“layoutSubvies”方法
1039
+ [self sd_layoutSubviews];
1040
+
1041
+ [self sd_layoutSubviewsHandle];
1042
+ }
1043
+
1044
+ - (void)sd_layoutSubviewsHandle{
1045
+
1046
+ if (self.sd_equalWidthSubviews.count) {
1047
+ __block CGFloat totalMargin = 0;
1048
+ [self.sd_equalWidthSubviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
1049
+ SDAutoLayoutModel *model = view.sd_layout;
1050
+ CGFloat left = model.left ? [model.left.value floatValue] : model.needsAutoResizeView.left_sd;
1051
+ totalMargin += (left + [model.right.value floatValue]);
1052
+ }];
1053
+ CGFloat averageWidth = (self.width_sd - totalMargin) / self.sd_equalWidthSubviews.count;
1054
+ [self.sd_equalWidthSubviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
1055
+ view.width_sd = averageWidth;
1056
+ view.fixedWidth = @(averageWidth);
1057
+ }];
1058
+ }
1059
+
1060
+ if (self.sd_categoryManager.flowItems.count && (self.sd_categoryManager.lastWidth != self.width_sd)) {
1061
+
1062
+ self.sd_categoryManager.lastWidth = self.width_sd;
1063
+
1064
+ NSInteger perRowItemsCount = self.sd_categoryManager.perRowItemsCount;
1065
+ CGFloat horizontalMargin = 0;
1066
+ CGFloat w = 0;
1067
+ if (self.sd_categoryManager.shouldShowAsAutoMarginViews) {
1068
+ w = self.sd_categoryManager.flowItemWidth;
1069
+ long itemsCount = self.sd_categoryManager.perRowItemsCount;
1070
+ if (itemsCount > 1) {
1071
+ horizontalMargin = (self.width_sd - (self.horizontalEdgeInset * 2) - itemsCount * w) / (itemsCount - 1);
1072
+ }
1073
+ } else {
1074
+ horizontalMargin = self.sd_categoryManager.horizontalMargin;
1075
+ w = (self.width_sd - (self.horizontalEdgeInset * 2) - (perRowItemsCount - 1) * horizontalMargin) / perRowItemsCount;
1076
+ }
1077
+ CGFloat verticalMargin = self.sd_categoryManager.verticalMargin;
1078
+
1079
+ __block UIView *referencedView = self;
1080
+ [self.sd_categoryManager.flowItems enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
1081
+ if (idx < perRowItemsCount) {
1082
+ if (idx == 0) {
1083
+ /* 保留
1084
+ BOOL shouldShowAsAutoMarginViews = self.sd_categoryManager.shouldShowAsAutoMarginViews;
1085
+ */
1086
+ view.sd_layout
1087
+ .leftSpaceToView(referencedView, self.horizontalEdgeInset)
1088
+ .topSpaceToView(referencedView, self.verticalEdgeInset)
1089
+ .widthIs(w);
1090
+ } else {
1091
+ view.sd_layout
1092
+ .leftSpaceToView(referencedView, horizontalMargin)
1093
+ .topEqualToView(referencedView)
1094
+ .widthIs(w);
1095
+ }
1096
+ referencedView = view;
1097
+ } else {
1098
+ referencedView = self.sd_categoryManager.flowItems[idx - perRowItemsCount];
1099
+ view.sd_layout
1100
+ .leftEqualToView(referencedView)
1101
+ .widthIs(w)
1102
+ .topSpaceToView(referencedView, verticalMargin);
1103
+ }
1104
+ }];
1105
+ }
1106
+
1107
+ if (self.autoLayoutModelsArray.count) {
1108
+
1109
+ NSMutableArray *caches = nil;
1110
+
1111
+ if ([self isKindOfClass:NSClassFromString(@"UITableViewCellContentView")] && self.sd_tableView) {
1112
+ caches = [self.sd_tableView.cellAutoHeightManager subviewFrameCachesWithIndexPath:self.sd_indexPath];
1113
+ }
1114
+
1115
+ [self.autoLayoutModelsArray enumerateObjectsUsingBlock:^(SDAutoLayoutModel *model, NSUInteger idx, BOOL *stop) {
1116
+ if (idx < caches.count) {
1117
+ CGRect originalFrame = model.needsAutoResizeView.frame;
1118
+ CGRect newFrame = [[caches objectAtIndex:idx] CGRectValue];
1119
+ if (CGRectEqualToRect(originalFrame, newFrame)) {
1120
+ [model.needsAutoResizeView setNeedsLayout];
1121
+ } else {
1122
+ model.needsAutoResizeView.frame = newFrame;
1123
+ }
1124
+ [self setupCornerRadiusWithView:model.needsAutoResizeView model:model];
1125
+ model.needsAutoResizeView.sd_categoryManager.hasSetFrameWithCache = YES;
1126
+ } else {
1127
+ if (model.needsAutoResizeView.sd_categoryManager.hasSetFrameWithCache) {
1128
+ model.needsAutoResizeView.sd_categoryManager.hasSetFrameWithCache = NO;
1129
+ }
1130
+ [self sd_resizeWithModel:model];
1131
+ }
1132
+ }];
1133
+ }
1134
+
1135
+ if (self.tag == kSDModelCellTag && [self isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) {
1136
+ UITableViewCell *cell = (UITableViewCell *)(self.superview);
1137
+ if ([cell isKindOfClass:NSClassFromString(@"UITableViewCellScrollView")]) {
1138
+ cell = (UITableViewCell *)cell.superview;
1139
+ }
1140
+ if ([cell isKindOfClass:[UITableViewCell class]]) {
1141
+ CGFloat height = 0;
1142
+ for (UIView *view in cell.sd_bottomViewsArray) {
1143
+ height = MAX(height, view.bottom_sd);
1144
+ }
1145
+ cell.autoHeight = height + cell.sd_bottomViewBottomMargin;
1146
+ }
1147
+ } else if (![self isKindOfClass:[UITableViewCell class]] && (self.sd_bottomViewsArray.count || self.sd_rightViewsArray.count)) {
1148
+ if (self.sd_categoryManager.hasSetFrameWithCache) {
1149
+ self.sd_categoryManager.hasSetFrameWithCache = NO;
1150
+ return;
1151
+ }
1152
+ CGFloat contentHeight = 0;
1153
+ CGFloat contentWidth = 0;
1154
+ if (self.sd_bottomViewsArray) {
1155
+ CGFloat height = 0;
1156
+ for (UIView *view in self.sd_bottomViewsArray) {
1157
+ height = MAX(height, view.bottom_sd);
1158
+ }
1159
+ contentHeight = height + self.sd_bottomViewBottomMargin;
1160
+ }
1161
+ if (self.sd_rightViewsArray) {
1162
+ CGFloat width = 0;
1163
+ for (UIView *view in self.sd_rightViewsArray) {
1164
+ width = MAX(width, view.right_sd);
1165
+ }
1166
+ contentWidth = width + self.sd_rightViewRightMargin;
1167
+ }
1168
+ if ([self isKindOfClass:[UIScrollView class]]) {
1169
+ UIScrollView *scrollView = (UIScrollView *)self;
1170
+ CGSize contentSize = scrollView.contentSize;
1171
+ if (contentHeight > 0) {
1172
+ contentSize.height = contentHeight;
1173
+ }
1174
+ if (contentWidth > 0) {
1175
+ contentSize.width = contentWidth;
1176
+ }
1177
+ if (contentSize.width <= 0) {
1178
+ contentSize.width = scrollView.width_sd;
1179
+ }
1180
+ if (!CGSizeEqualToSize(contentSize, scrollView.contentSize)) {
1181
+ scrollView.contentSize = contentSize;
1182
+ }
1183
+ } else {
1184
+ // 如果这里出现循环调用情况请把demo发送到gsdios@126.com,谢谢配合。
1185
+ if (self.sd_bottomViewsArray.count && (floorf(contentHeight) != floorf(self.height_sd))) {
1186
+ self.height_sd = contentHeight;
1187
+ self.fixedHeight = @(self.height_sd);
1188
+ }
1189
+
1190
+ if (self.sd_rightViewsArray.count && (floorf(contentWidth) != floorf(self.width_sd))) {
1191
+ self.width_sd = contentWidth;
1192
+ self.fixedWidth = @(self.width_sd);
1193
+ }
1194
+ }
1195
+
1196
+ SDAutoLayoutModel *model = self.ownLayoutModel;
1197
+
1198
+ if (![self isKindOfClass:[UIScrollView class]] && self.sd_rightViewsArray.count && (model.right || model.equalRight || model.centerX || model.equalCenterX)) {
1199
+ self.fixedWidth = @(self.width);
1200
+ if (model.right || model.equalRight) {
1201
+ [self layoutRightWithView:self model:model];
1202
+ } else {
1203
+ [self layoutLeftWithView:self model:model];
1204
+ }
1205
+ self.fixedWidth = nil;
1206
+ }
1207
+
1208
+ if (![self isKindOfClass:[UIScrollView class]] && self.sd_bottomViewsArray.count && (model.bottom || model.equalBottom || model.centerY || model.equalCenterY)) {
1209
+ self.fixedHeight = @(self.height);
1210
+ if (model.bottom || model.equalBottom) {
1211
+ [self layoutBottomWithView:self model:model];
1212
+ } else {
1213
+ [self layoutTopWithView:self model:model];
1214
+ }
1215
+ self.fixedHeight = nil;
1216
+ }
1217
+
1218
+ if (self.didFinishAutoLayoutBlock) {
1219
+ self.didFinishAutoLayoutBlock(self.frame);
1220
+ }
1221
+ }
1222
+ }
1223
+
1224
+ - (void)sd_resizeWithModel:(SDAutoLayoutModel *)model
1225
+ {
1226
+ UIView *view = model.needsAutoResizeView;
1227
+
1228
+ if (!view || view.sd_isClosingAutoLayout) return;
1229
+
1230
+ if (view.sd_maxWidth && (model.rightSpaceToView || model.rightEqualToView)) { // 靠右布局前提设置
1231
+ [self layoutAutoWidthWidthView:view model:model];
1232
+ view.fixedWidth = @(view.width_sd);
1233
+ }
1234
+
1235
+ [self layoutWidthWithView:view model:model];
1236
+
1237
+ [self layoutHeightWithView:view model:model];
1238
+
1239
+ [self layoutLeftWithView:view model:model];
1240
+
1241
+ [self layoutRightWithView:view model:model];
1242
+
1243
+ if (view.autoHeightRatioValue && view.width_sd > 0 && (model.bottomEqualToView || model.bottomSpaceToView)) { // 底部布局前提设置
1244
+ [self layoutAutoHeightWidthView:view model:model];
1245
+ view.fixedHeight = @(view.height_sd);
1246
+ }
1247
+
1248
+ if (view.autoWidthRatioValue) {
1249
+ view.fixedWidth = @(view.height_sd * [view.autoWidthRatioValue floatValue]);
1250
+ }
1251
+
1252
+
1253
+ [self layoutTopWithView:view model:model];
1254
+
1255
+ [self layoutBottomWithView:view model:model];
1256
+
1257
+ if (view.sd_maxWidth) {
1258
+ [self layoutAutoWidthWidthView:view model:model];
1259
+ }
1260
+
1261
+ if (model.maxWidth && [model.maxWidth floatValue] < view.width_sd) {
1262
+ view.width_sd = [model.maxWidth floatValue];
1263
+ }
1264
+
1265
+ if (model.minWidth && [model.minWidth floatValue] > view.width_sd) {
1266
+ view.width_sd = [model.minWidth floatValue];
1267
+ }
1268
+
1269
+ if (view.autoHeightRatioValue && view.width_sd > 0) {
1270
+ [self layoutAutoHeightWidthView:view model:model];
1271
+ }
1272
+
1273
+ if (model.maxHeight && [model.maxHeight floatValue] < view.height_sd) {
1274
+ view.height_sd = [model.maxHeight floatValue];
1275
+ }
1276
+
1277
+ if (model.minHeight && [model.minHeight floatValue] > view.height_sd) {
1278
+ view.height_sd = [model.minHeight floatValue];
1279
+ }
1280
+
1281
+ if (model.widthEqualHeight) {
1282
+ view.width_sd = view.height_sd;
1283
+ }
1284
+
1285
+ if (model.heightEqualWidth) {
1286
+ view.height_sd = view.width_sd;
1287
+ }
1288
+
1289
+ if (view.didFinishAutoLayoutBlock) {
1290
+ view.didFinishAutoLayoutBlock(view.frame);
1291
+ }
1292
+
1293
+ if (view.sd_bottomViewsArray.count || view.sd_rightViewsArray.count) {
1294
+ [view layoutSubviews];
1295
+ }
1296
+
1297
+ [self setupCornerRadiusWithView:view model:model];
1298
+ }
1299
+
1300
+ - (void)layoutAutoHeightWidthView:(UIView *)view model:(SDAutoLayoutModel *)model
1301
+ {
1302
+ if ([view.autoHeightRatioValue floatValue] > 0) {
1303
+ view.height_sd = view.width_sd * [view.autoHeightRatioValue floatValue];
1304
+ } else {
1305
+ if ([view isKindOfClass:[UILabel class]]) {
1306
+ UILabel *label = (UILabel *)view;
1307
+ label.numberOfLines = 0;
1308
+ if (label.text.length) {
1309
+ if (!label.isAttributedContent) {
1310
+ CGRect rect = [label.text boundingRectWithSize:CGSizeMake(label.width_sd, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : label.font} context:nil];
1311
+ label.height_sd = rect.size.height + 0.1;
1312
+ } else {
1313
+ [label sizeToFit];
1314
+ }
1315
+ } else {
1316
+ label.height_sd = 0;
1317
+ }
1318
+ } else {
1319
+ view.height_sd = 0;
1320
+ }
1321
+ }
1322
+ }
1323
+
1324
+ - (void)layoutAutoWidthWidthView:(UIView *)view model:(SDAutoLayoutModel *)model
1325
+ {
1326
+ if ([view isKindOfClass:[UILabel class]]) {
1327
+ UILabel *label = (UILabel *)view;
1328
+ CGFloat width = [view.sd_maxWidth floatValue] > 0 ? [view.sd_maxWidth floatValue] : MAXFLOAT;
1329
+ label.numberOfLines = 1;
1330
+ if (label.text.length) {
1331
+ if (!label.isAttributedContent) {
1332
+ CGRect rect = [label.text boundingRectWithSize:CGSizeMake(MAXFLOAT, label.height_sd) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : label.font} context:nil];
1333
+ if (rect.size.width > width) {
1334
+ rect.size.width = width;
1335
+ }
1336
+ label.width_sd = rect.size.width + 0.1;
1337
+ } else{
1338
+ [label sizeToFit];
1339
+ if (label.width_sd > width) {
1340
+ label.width_sd = width;
1341
+ }
1342
+ }
1343
+ } else {
1344
+ label.size_sd = CGSizeZero;
1345
+ }
1346
+ }
1347
+ }
1348
+
1349
+ - (void)layoutWidthWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1350
+ {
1351
+ if (model.width) {
1352
+ view.width_sd = [model.width.value floatValue];
1353
+ view.fixedWidth = @(view.width_sd);
1354
+ } else if (model.ratio_width) {
1355
+ view.width_sd = model.ratio_width.refView.width_sd * [model.ratio_width.value floatValue];
1356
+ view.fixedWidth = @(view.width_sd);
1357
+ }
1358
+ }
1359
+
1360
+ - (void)layoutHeightWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1361
+ {
1362
+ if (model.height) {
1363
+ view.height_sd = [model.height.value floatValue];
1364
+ view.fixedHeight = @(view.height_sd);
1365
+ } else if (model.ratio_height) {
1366
+ view.height_sd = [model.ratio_height.value floatValue] * model.ratio_height.refView.height_sd;
1367
+ view.fixedHeight = @(view.height_sd);
1368
+ }
1369
+ }
1370
+
1371
+ - (void)layoutLeftWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1372
+ {
1373
+ if (model.left) {
1374
+ if (view.superview == model.left.refView) {
1375
+ if (!view.fixedWidth) { // view.autoLeft && view.autoRight
1376
+ view.width_sd = view.right_sd - [model.left.value floatValue];
1377
+ }
1378
+ view.left_sd = [model.left.value floatValue];
1379
+ } else {
1380
+ if (model.left.refViewsArray.count) {
1381
+ CGFloat lastRefRight = 0;
1382
+ for (UIView *ref in model.left.refViewsArray) {
1383
+ if ([ref isKindOfClass:[UIView class]] && ref.right_sd > lastRefRight) {
1384
+ model.left.refView = ref;
1385
+ lastRefRight = ref.right_sd;
1386
+ }
1387
+ }
1388
+ }
1389
+ if (!view.fixedWidth) { // view.autoLeft && view.autoRight
1390
+ view.width_sd = view.right_sd - model.left.refView.right_sd - [model.left.value floatValue];
1391
+ }
1392
+ view.left_sd = model.left.refView.right_sd + [model.left.value floatValue];
1393
+ }
1394
+
1395
+ } else if (model.equalLeft) {
1396
+ if (!view.fixedWidth) {
1397
+ if (model.needsAutoResizeView == view.superview) {
1398
+ view.width_sd = view.right_sd - (0 + model.equalLeft.offset);
1399
+ } else {
1400
+ view.width_sd = view.right_sd - (model.equalLeft.refView.left_sd + model.equalLeft.offset);
1401
+ }
1402
+ }
1403
+ if (view.superview == model.equalLeft.refView) {
1404
+ view.left_sd = 0 + model.equalLeft.offset;
1405
+ } else {
1406
+ view.left_sd = model.equalLeft.refView.left_sd + model.equalLeft.offset;
1407
+ }
1408
+ } else if (model.equalCenterX) {
1409
+ if (view.superview == model.equalCenterX.refView) {
1410
+ view.centerX_sd = model.equalCenterX.refView.width_sd * 0.5 + model.equalCenterX.offset;
1411
+ } else {
1412
+ view.centerX_sd = model.equalCenterX.refView.centerX_sd + model.equalCenterX.offset;
1413
+ }
1414
+ } else if (model.centerX) {
1415
+ view.centerX_sd = [model.centerX floatValue];
1416
+ }
1417
+ }
1418
+
1419
+ - (void)layoutRightWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1420
+ {
1421
+ if (model.right) {
1422
+ if (view.superview == model.right.refView) {
1423
+ if (!view.fixedWidth) { // view.autoLeft && view.autoRight
1424
+ view.width_sd = model.right.refView.width_sd - view.left_sd - [model.right.value floatValue];
1425
+ }
1426
+ view.right_sd = model.right.refView.width_sd - [model.right.value floatValue];
1427
+ } else {
1428
+ if (!view.fixedWidth) { // view.autoLeft && view.autoRight
1429
+ view.width_sd = model.right.refView.left_sd - view.left_sd - [model.right.value floatValue];
1430
+ }
1431
+ view.right_sd = model.right.refView.left_sd - [model.right.value floatValue];
1432
+ }
1433
+ } else if (model.equalRight) {
1434
+ if (!view.fixedWidth) {
1435
+ if (model.equalRight.refView == view.superview) {
1436
+ view.width_sd = model.equalRight.refView.width_sd - view.left_sd + model.equalRight.offset;
1437
+ } else {
1438
+ view.width_sd = model.equalRight.refView.right_sd - view.left_sd + model.equalRight.offset;
1439
+ }
1440
+ }
1441
+
1442
+ view.right_sd = model.equalRight.refView.right_sd + model.equalRight.offset;
1443
+ if (view.superview == model.equalRight.refView) {
1444
+ view.right_sd = model.equalRight.refView.width_sd + model.equalRight.offset;
1445
+ }
1446
+
1447
+ }
1448
+ }
1449
+
1450
+ - (void)layoutTopWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1451
+ {
1452
+ if (model.top) {
1453
+ if (view.superview == model.top.refView) {
1454
+ if (!view.fixedHeight) { // view.autoTop && view.autoBottom && view.bottom
1455
+ view.height_sd = view.bottom_sd - [model.top.value floatValue];
1456
+ }
1457
+ view.top_sd = [model.top.value floatValue];
1458
+ } else {
1459
+ if (model.top.refViewsArray.count) {
1460
+ CGFloat lastRefBottom = 0;
1461
+ for (UIView *ref in model.top.refViewsArray) {
1462
+ if ([ref isKindOfClass:[UIView class]] && ref.bottom_sd > lastRefBottom) {
1463
+ model.top.refView = ref;
1464
+ lastRefBottom = ref.bottom_sd;
1465
+ }
1466
+ }
1467
+ }
1468
+ if (!view.fixedHeight) { // view.autoTop && view.autoBottom && view.bottom
1469
+ view.height_sd = view.bottom_sd - model.top.refView.bottom_sd - [model.top.value floatValue];
1470
+ }
1471
+ view.top_sd = model.top.refView.bottom_sd + [model.top.value floatValue];
1472
+ }
1473
+ } else if (model.equalTop) {
1474
+ if (view.superview == model.equalTop.refView) {
1475
+ if (!view.fixedHeight) {
1476
+ view.height_sd = view.bottom_sd - model.equalTop.offset;
1477
+ }
1478
+ view.top_sd = 0 + model.equalTop.offset;
1479
+ } else {
1480
+ if (!view.fixedHeight) {
1481
+ view.height_sd = view.bottom_sd - (model.equalTop.refView.top_sd + model.equalTop.offset);
1482
+ }
1483
+ view.top_sd = model.equalTop.refView.top_sd + model.equalTop.offset;
1484
+ }
1485
+ } else if (model.equalCenterY) {
1486
+ if (view.superview == model.equalCenterY.refView) {
1487
+ view.centerY_sd = model.equalCenterY.refView.height_sd * 0.5 + model.equalCenterY.offset;
1488
+ } else {
1489
+ view.centerY_sd = model.equalCenterY.refView.centerY_sd + model.equalCenterY.offset;
1490
+ }
1491
+ } else if (model.centerY) {
1492
+ view.centerY_sd = [model.centerY floatValue];
1493
+ }
1494
+ }
1495
+
1496
+ - (void)layoutBottomWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1497
+ {
1498
+ if (model.bottom) {
1499
+ if (view.superview == model.bottom.refView) {
1500
+ if (!view.fixedHeight) {
1501
+ view.height_sd = view.superview.height_sd - view.top_sd - [model.bottom.value floatValue];
1502
+ }
1503
+ view.bottom_sd = model.bottom.refView.height_sd - [model.bottom.value floatValue];
1504
+ } else {
1505
+ if (!view.fixedHeight) {
1506
+ view.height_sd = model.bottom.refView.top_sd - view.top_sd - [model.bottom.value floatValue];
1507
+ }
1508
+ view.bottom_sd = model.bottom.refView.top_sd - [model.bottom.value floatValue];
1509
+ }
1510
+
1511
+ } else if (model.equalBottom) {
1512
+ if (view.superview == model.equalBottom.refView) {
1513
+ if (!view.fixedHeight) {
1514
+ view.height_sd = view.superview.height_sd - view.top_sd + model.equalBottom.offset;
1515
+ }
1516
+ view.bottom_sd = model.equalBottom.refView.height_sd + model.equalBottom.offset;
1517
+ } else {
1518
+ if (!view.fixedHeight) {
1519
+ view.height_sd = model.equalBottom.refView.bottom_sd - view.top_sd + model.equalBottom.offset;
1520
+ }
1521
+ view.bottom_sd = model.equalBottom.refView.bottom_sd + model.equalBottom.offset;
1522
+ }
1523
+ }
1524
+ if (model.widthEqualHeight && !view.fixedHeight) {
1525
+ [self layoutRightWithView:view model:model];
1526
+ }
1527
+ }
1528
+
1529
+
1530
+ - (void)setupCornerRadiusWithView:(UIView *)view model:(SDAutoLayoutModel *)model
1531
+ {
1532
+ CGFloat cornerRadius = view.layer.cornerRadius;
1533
+ CGFloat newCornerRadius = 0;
1534
+
1535
+ if (view.sd_cornerRadius && (cornerRadius != [view.sd_cornerRadius floatValue])) {
1536
+ newCornerRadius = [view.sd_cornerRadius floatValue];
1537
+ } else if (view.sd_cornerRadiusFromWidthRatio && (cornerRadius != [view.sd_cornerRadiusFromWidthRatio floatValue] * view.width_sd)) {
1538
+ newCornerRadius = view.width_sd * [view.sd_cornerRadiusFromWidthRatio floatValue];
1539
+ } else if (view.sd_cornerRadiusFromHeightRatio && (cornerRadius != view.height_sd * [view.sd_cornerRadiusFromHeightRatio floatValue])) {
1540
+ newCornerRadius = view.height_sd * [view.sd_cornerRadiusFromHeightRatio floatValue];
1541
+ }
1542
+
1543
+ if (newCornerRadius > 0) {
1544
+ view.layer.cornerRadius = newCornerRadius;
1545
+ view.clipsToBounds = YES;
1546
+ }
1547
+ }
1548
+
1549
+ - (void)addAutoLayoutModel:(SDAutoLayoutModel *)model
1550
+ {
1551
+ [self.autoLayoutModelsArray addObject:model];
1552
+ }
1553
+
1554
+ @end
1555
+
1556
+ @implementation UIButton (SDAutoLayoutButton)
1557
+
1558
+ + (void)load
1559
+ {
1560
+ static dispatch_once_t onceToken;
1561
+ dispatch_once(&onceToken, ^{
1562
+ NSString *selString = @"layoutSubviews";
1563
+ NSString *mySelString = [@"sd_button_" stringByAppendingString:selString];
1564
+
1565
+ Method originalMethod = class_getInstanceMethod(self, NSSelectorFromString(selString));
1566
+ Method myMethod = class_getInstanceMethod(self, NSSelectorFromString(mySelString));
1567
+ method_exchangeImplementations(originalMethod, myMethod);
1568
+ });
1569
+ }
1570
+
1571
+ - (void)sd_button_layoutSubviews
1572
+ {
1573
+ // 如果程序崩溃在这行代码说明是你的view在执行“layoutSubvies”方法时出了问题而不是在此自动布局库内部出现了问题,请检查你的“layoutSubvies”方法
1574
+ [self sd_button_layoutSubviews];
1575
+
1576
+ [self sd_layoutSubviewsHandle];
1577
+
1578
+ }
1579
+
1580
+ @end
1581
+
1582
+
1583
+ @implementation UIView (SDChangeFrame)
1584
+
1585
+ - (BOOL)shouldReadjustFrameBeforeStoreCache
1586
+ {
1587
+ return self.sd_categoryManager.shouldReadjustFrameBeforeStoreCache;
1588
+ }
1589
+
1590
+ - (void)setShouldReadjustFrameBeforeStoreCache:(BOOL)shouldReadjustFrameBeforeStoreCache
1591
+ {
1592
+ self.sd_categoryManager.shouldReadjustFrameBeforeStoreCache = shouldReadjustFrameBeforeStoreCache;
1593
+ }
1594
+
1595
+ - (CGFloat)left_sd {
1596
+ return self.frame.origin.x;
1597
+ }
1598
+
1599
+ - (void)setLeft_sd:(CGFloat)x_sd {
1600
+ CGRect frame = self.frame;
1601
+ frame.origin.x = x_sd;
1602
+ self.frame = frame;
1603
+ }
1604
+
1605
+ - (CGFloat)top_sd {
1606
+ return self.frame.origin.y;
1607
+ }
1608
+
1609
+ - (void)setTop_sd:(CGFloat)y_sd {
1610
+ CGRect frame = self.frame;
1611
+ frame.origin.y = y_sd;
1612
+ self.frame = frame;
1613
+ }
1614
+
1615
+ - (CGFloat)right_sd {
1616
+ return self.frame.origin.x + self.frame.size.width;
1617
+ }
1618
+
1619
+ - (void)setRight_sd:(CGFloat)right_sd {
1620
+ CGRect frame = self.frame;
1621
+ frame.origin.x = right_sd - frame.size.width;
1622
+ self.frame = frame;
1623
+ }
1624
+
1625
+ - (CGFloat)bottom_sd {
1626
+ return self.frame.origin.y + self.frame.size.height;
1627
+ }
1628
+
1629
+ - (void)setBottom_sd:(CGFloat)bottom_sd {
1630
+ CGRect frame = self.frame;
1631
+ frame.origin.y = bottom_sd - frame.size.height;
1632
+ self.frame = frame;
1633
+ }
1634
+
1635
+ - (CGFloat)centerX_sd
1636
+ {
1637
+ return self.left_sd + self.width_sd * 0.5;
1638
+ }
1639
+
1640
+ - (void)setCenterX_sd:(CGFloat)centerX_sd
1641
+ {
1642
+ self.left_sd = centerX_sd - self.width_sd * 0.5;
1643
+ }
1644
+
1645
+ - (CGFloat)centerY_sd
1646
+ {
1647
+ return self.top_sd + self.height_sd * 0.5;
1648
+ }
1649
+
1650
+ - (void)setCenterY_sd:(CGFloat)centerY_sd
1651
+ {
1652
+ self.top_sd = centerY_sd - self.height_sd * 0.5;
1653
+ }
1654
+
1655
+ - (CGFloat)width_sd {
1656
+ return self.frame.size.width;
1657
+ }
1658
+
1659
+ - (void)setWidth_sd:(CGFloat)width_sd {
1660
+ if (self.ownLayoutModel.widthEqualHeight) {
1661
+ if (width_sd != self.height_sd) return;
1662
+ }
1663
+ [self setWidth:width_sd];
1664
+ if (self.ownLayoutModel.heightEqualWidth) {
1665
+ self.height_sd = width_sd;
1666
+ }
1667
+ }
1668
+
1669
+ - (CGFloat)height_sd {
1670
+ return self.frame.size.height;
1671
+ }
1672
+
1673
+ - (void)setHeight_sd:(CGFloat)height_sd {
1674
+ if (self.ownLayoutModel.heightEqualWidth) {
1675
+ if (height_sd != self.width_sd) return;
1676
+ }
1677
+ [self setHeight:height_sd];
1678
+ if (self.ownLayoutModel.widthEqualHeight) {
1679
+ self.width_sd = height_sd;
1680
+ }
1681
+ }
1682
+
1683
+ - (CGPoint)origin_sd {
1684
+ return self.frame.origin;
1685
+ }
1686
+
1687
+ - (void)setOrigin_sd:(CGPoint)origin_sd {
1688
+ CGRect frame = self.frame;
1689
+ frame.origin = origin_sd;
1690
+ self.frame = frame;
1691
+ }
1692
+
1693
+ - (CGSize)size_sd {
1694
+ return self.frame.size;
1695
+ }
1696
+
1697
+ - (void)setSize_sd:(CGSize)size_sd {
1698
+ [self setSize:size_sd];
1699
+ }
1700
+
1701
+ - (void)setWidth:(CGFloat)width
1702
+ {
1703
+ CGRect frame = self.frame;
1704
+ frame.size.width = width;
1705
+ self.frame = frame;
1706
+ }
1707
+
1708
+ - (void)setHeight:(CGFloat)height {
1709
+ CGRect frame = self.frame;
1710
+ frame.size.height = height;
1711
+ self.frame = frame;
1712
+ }
1713
+
1714
+ - (void)setSize:(CGSize)size {
1715
+ CGRect frame = self.frame;
1716
+ frame.size = size;
1717
+ self.frame = frame;
1718
+ }
1719
+
1720
+ // 兼容旧版本
1721
+
1722
+ - (CGFloat)left
1723
+ {
1724
+ return self.left_sd;
1725
+ }
1726
+
1727
+ - (void)setLeft:(CGFloat)left
1728
+ {
1729
+ self.left_sd = left;
1730
+ }
1731
+
1732
+ - (CGFloat)right
1733
+ {
1734
+ return self.right_sd;
1735
+ }
1736
+
1737
+ - (void)setRight:(CGFloat)right
1738
+ {
1739
+ self.right_sd = right;
1740
+ }
1741
+
1742
+ - (CGFloat)width
1743
+ {
1744
+ return self.width_sd;
1745
+ }
1746
+
1747
+ - (CGFloat)height
1748
+ {
1749
+ return self.height_sd;
1750
+ }
1751
+
1752
+ - (CGFloat)top
1753
+ {
1754
+ return self.top_sd;
1755
+ }
1756
+
1757
+ - (void)setTop:(CGFloat)top
1758
+ {
1759
+ self.top_sd = top;
1760
+ }
1761
+
1762
+ - (CGFloat)bottom
1763
+ {
1764
+ return self.bottom_sd;
1765
+ }
1766
+
1767
+ - (void)setBottom:(CGFloat)bottom
1768
+ {
1769
+ self.bottom_sd = bottom;
1770
+ }
1771
+
1772
+ - (CGFloat)centerX
1773
+ {
1774
+ return self.centerX_sd;
1775
+ }
1776
+
1777
+ - (void)setCenterX:(CGFloat)centerX
1778
+ {
1779
+ self.centerX_sd = centerX;
1780
+ }
1781
+
1782
+ - (CGFloat)centerY
1783
+ {
1784
+ return self.centerY_sd;
1785
+ }
1786
+
1787
+ - (void)setCenterY:(CGFloat)centerY
1788
+ {
1789
+ self.centerY_sd = centerY;
1790
+ }
1791
+
1792
+ - (CGPoint)origin
1793
+ {
1794
+ return self.origin_sd;
1795
+ }
1796
+
1797
+ - (void)setOrigin:(CGPoint)origin
1798
+ {
1799
+ self.origin_sd = origin;
1800
+ }
1801
+
1802
+ - (CGSize)size
1803
+ {
1804
+ return self.size_sd;
1805
+ }
1806
+
1807
+ @end
1808
+
1809
+ @implementation SDUIViewCategoryManager
1810
+
1811
+ @end
1812
+