iOS:implement MaxWidth and MaxHeight
This commit is contained in:
parent
91787fb0af
commit
870a7e74af
@ -88,6 +88,10 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
|||||||
|
|
||||||
@property(nonatomic, assign) BOOL disabled;
|
@property(nonatomic, assign) BOOL disabled;
|
||||||
|
|
||||||
|
@property(nonatomic, assign) CGFloat maxWidth;
|
||||||
|
|
||||||
|
@property(nonatomic, assign) CGFloat maxHeight;
|
||||||
|
|
||||||
- (instancetype)init;
|
- (instancetype)init;
|
||||||
|
|
||||||
- (void)apply;
|
- (void)apply;
|
||||||
|
@ -63,6 +63,8 @@ - (instancetype)init {
|
|||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_widthSpec = DoricLayoutJust;
|
_widthSpec = DoricLayoutJust;
|
||||||
_heightSpec = DoricLayoutJust;
|
_heightSpec = DoricLayoutJust;
|
||||||
|
_maxWidth = -1;
|
||||||
|
_maxHeight = -1;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -91,6 +93,25 @@ - (void)measure:(CGSize)targetSize {
|
|||||||
[self measureContent:CGSizeMake(
|
[self measureContent:CGSizeMake(
|
||||||
self.measuredWidth - self.paddingLeft - self.paddingRight,
|
self.measuredWidth - self.paddingLeft - self.paddingRight,
|
||||||
self.measuredHeight - self.paddingTop - self.paddingBottom)];
|
self.measuredHeight - self.paddingTop - self.paddingBottom)];
|
||||||
|
|
||||||
|
BOOL needRemeasure = NO;
|
||||||
|
if (self.maxWidth >= 0) {
|
||||||
|
if (self.measuredWidth > self.maxWidth) {
|
||||||
|
self.measuredWidth = self.maxWidth;
|
||||||
|
needRemeasure = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (self.maxHeight > 0) {
|
||||||
|
if (self.measuredHeight > self.maxHeight) {
|
||||||
|
self.measuredHeight = self.maxHeight;
|
||||||
|
needRemeasure = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needRemeasure) {
|
||||||
|
[self measureContent:CGSizeMake(
|
||||||
|
self.measuredWidth - self.paddingLeft - self.paddingRight,
|
||||||
|
self.measuredHeight - self.paddingTop - self.paddingBottom)];
|
||||||
|
}
|
||||||
self.resolved = YES;
|
self.resolved = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
#import "Doric.h"
|
#import "Doric.h"
|
||||||
|
|
||||||
@interface DoricTextView : UILabel
|
@interface DoricTextView : UILabel
|
||||||
@property(nonatomic, assign) CGFloat maxWidth;
|
|
||||||
@property(nonatomic, assign) CGFloat maxHeight;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricTextView
|
@implementation DoricTextView
|
||||||
@ -50,8 +48,6 @@ @implementation DoricTextNode
|
|||||||
- (UILabel *)build {
|
- (UILabel *)build {
|
||||||
return [[[DoricTextView alloc] init] also:^(DoricTextView *it) {
|
return [[[DoricTextView alloc] init] also:^(DoricTextView *it) {
|
||||||
it.textAlignment = NSTextAlignmentCenter;
|
it.textAlignment = NSTextAlignmentCenter;
|
||||||
it.maxWidth = -1;
|
|
||||||
it.maxHeight = -1;
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,13 +105,9 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
|||||||
}
|
}
|
||||||
view.font = font;
|
view.font = font;
|
||||||
} else if ([name isEqualToString:@"maxWidth"]) {
|
} else if ([name isEqualToString:@"maxWidth"]) {
|
||||||
if ([view isKindOfClass:DoricTextView.class]) {
|
view.doricLayout.maxWidth = [prop floatValue];
|
||||||
((DoricTextView *) view).maxWidth = [prop floatValue];
|
|
||||||
}
|
|
||||||
} else if ([name isEqualToString:@"maxHeight"]) {
|
} else if ([name isEqualToString:@"maxHeight"]) {
|
||||||
if ([view isKindOfClass:DoricTextView.class]) {
|
view.doricLayout.maxHeight = [prop floatValue];
|
||||||
((DoricTextView *) view).maxHeight = [prop floatValue];
|
|
||||||
}
|
|
||||||
} else if ([name isEqualToString:@"font"]) {
|
} else if ([name isEqualToString:@"font"]) {
|
||||||
NSString *iconfont = prop;
|
NSString *iconfont = prop;
|
||||||
UIFont *font = [UIFont fontWithName:iconfont size:view.font.pointSize];
|
UIFont *font = [UIFont fontWithName:iconfont size:view.font.pointSize];
|
||||||
|
Reference in New Issue
Block a user