|
|
@@ -8,10 +8,43 @@
|
|
|
|
|
|
#import "RAEditLabelModel.h"
|
|
|
|
|
|
-@implementation RAEditLabelModel
|
|
|
+static const CGFloat SpaceWidth = 10.0f;
|
|
|
+static const CGFloat SpaceHeight = 37.0f;
|
|
|
+
|
|
|
+@implementation RAEditLabelModel {
|
|
|
+ CGFloat _height;
|
|
|
+}
|
|
|
|
|
|
- (CGFloat)height {
|
|
|
- return 55.0f;
|
|
|
+ if (_height <= 0) {
|
|
|
+ [self caculateValueHeight];
|
|
|
+ }
|
|
|
+ return _height;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setValue:(NSString *)value {
|
|
|
+ _value = value;
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
+ [self caculateValueHeight];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)caculateValueHeight {
|
|
|
+
|
|
|
+ CGFloat w = [UIScreen mainScreen].bounds.size.width;
|
|
|
+ if (w <= 0) {
|
|
|
+ w = CGRectGetWidth([UIScreen mainScreen].bounds);
|
|
|
+ }
|
|
|
+
|
|
|
+ CGFloat h = [self.value boundingRectWithSize:CGSizeMake(w - SpaceWidth, FLT_MAX)
|
|
|
+ options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
|
|
|
+ attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]}
|
|
|
+ context:nil].size.height;
|
|
|
+ _height = h + SpaceHeight;
|
|
|
+ if (_height < 55.0f) {
|
|
|
+ _height = 55.0f;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@end
|