iOS:Text's max width and max height can only be affected while >0

This commit is contained in:
pengfei.zhou 2020-03-25 14:07:24 +08:00 committed by osborn
parent 139a8775d4
commit d088e30f38

View File

@ -39,10 +39,10 @@ - (CGSize)measureSize:(CGSize)targetSize {
CGSize measuredSize = [super measureSize:targetSize];
CGFloat measuredWidth = measuredSize.width;
CGFloat measuredHeight = measuredSize.height;
if (self.maxWidth > 0) {
if (self.maxWidth >= 0) {
measuredWidth = MIN(self.maxWidth, measuredSize.width);
}
if (self.maxHeight > 0) {
if (self.maxHeight >= 0) {
measuredHeight = MIN(self.maxHeight, measuredSize.height);
}
return CGSizeMake(measuredWidth, measuredHeight);
@ -55,8 +55,10 @@ @interface DoricTextNode ()
@implementation DoricTextNode
- (UILabel *)build {
return [[[DoricTextView alloc] init] also:^(UILabel *it) {
return [[[DoricTextView alloc] init] also:^(DoricTextView *it) {
it.textAlignment = NSTextAlignmentCenter;
it.maxWidth = -1;
it.maxHeight = -1;
}];
}