Prechádzať zdrojové kódy

完善一些问题

1.箭头、圈圈位置自适应
2.一些PR代码调整
M了个J 9 rokov pred
rodič
commit
0216f1fd39

+ 1 - 1
MJRefresh.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
     s.name         = 'MJRefresh'
-    s.version      = '3.1.0'
+    s.version      = '3.1.1'
     s.summary      = 'An easy way to use pull-to-refresh'
     s.homepage     = 'https://github.com/CoderMJLee/MJRefresh'
     s.license      = 'MIT'

+ 1 - 0
MJRefresh/Base/MJRefreshComponent.h

@@ -93,4 +93,5 @@ typedef void (^MJRefreshComponentRefreshingBlock)();
 
 @interface UILabel(MJRefresh)
 + (instancetype)mj_label;
+- (CGFloat)mj_textWith;
 @end

+ 27 - 0
MJRefresh/Base/MJRefreshComponent.m

@@ -165,6 +165,13 @@ - (NSString *)localizedStringForKey:(NSString *)key withDefault:(NSString *)defa
     return [[NSBundle mainBundle] localizedStringForKey:key value:defaultString table:nil];
 }
 
+- (void)setState:(MJRefreshState)state
+{
+    _state = state;
+    
+    [self setNeedsLayout];
+}
+
 #pragma mark 进入刷新状态
 - (void)beginRefreshing
 {
@@ -258,4 +265,24 @@ + (instancetype)mj_label
     label.backgroundColor = [UIColor clearColor];
     return label;
 }
+
+- (CGFloat)mj_textWith {
+    CGFloat stringWidth = 0;
+    CGSize size = CGSizeMake(MAXFLOAT, MAXFLOAT);
+    if (self.text.length > 0) {
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
+        stringWidth =[self.text
+                      boundingRectWithSize:size
+                      options:NSStringDrawingUsesLineFragmentOrigin
+                      attributes:@{NSFontAttributeName:self.font}
+                      context:nil].size.width;
+#else
+        
+        stringWidth = [self.text sizeWithFont:self.font
+                             constrainedToSize:size
+                                 lineBreakMode:NSLineBreakByCharWrapping].width;
+#endif
+    }
+    return stringWidth;
+}
 @end

+ 1 - 8
MJRefresh/Base/MJRefreshHeader.m

@@ -130,17 +130,10 @@ - (void)setState:(MJRefreshState)state
             } completion:^(BOOL finished) {
                 [self executeRefreshingCallback];
             }];
-         }];
+         });
     }
 }
 
-- (void)drawRect:(CGRect)rect
-{
-    [super drawRect:rect];
-    
-    
-}
-
 #pragma mark - 公共方法
 - (void)endRefreshing
 {

+ 1 - 1
MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m

@@ -77,7 +77,7 @@ - (void)placeSubviews
         self.gifView.contentMode = UIViewContentModeCenter;
     } else {
         self.gifView.contentMode = UIViewContentModeRight;
-        self.gifView.mj_w = self.mj_w * 0.5 - 90;
+        self.gifView.mj_w = self.mj_w * 0.5 - 20 - self.stateLabel.mj_textWith * 0.5;
     }
 }
 

+ 1 - 1
MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m

@@ -48,7 +48,7 @@ - (void)placeSubviews
     // 圈圈
     CGFloat loadingCenterX = self.mj_w * 0.5;
     if (!self.isRefreshingTitleHidden) {
-        loadingCenterX -= 100;
+        loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + 20;
     }
     CGFloat loadingCenterY = self.mj_h * 0.5;
     self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY);

+ 1 - 1
MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m

@@ -88,7 +88,7 @@ - (void)placeSubviews
         self.gifView.contentMode = UIViewContentModeCenter;
     } else {
         self.gifView.contentMode = UIViewContentModeRight;
-        self.gifView.mj_w = self.mj_w * 0.5 - 90;
+        self.gifView.mj_w = self.mj_w * 0.5 - 20 - self.stateLabel.mj_textWith * 0.5;
     }
 }
 

+ 1 - 1
MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m

@@ -60,7 +60,7 @@ - (void)placeSubviews
     // 箭头的中心点
     CGFloat arrowCenterX = self.mj_w * 0.5;
     if (!self.stateLabel.hidden) {
-        arrowCenterX -= 100;
+        arrowCenterX -= 20 + self.stateLabel.mj_textWith * 0.5;
     }
     CGFloat arrowCenterY = self.mj_h * 0.5;
     CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);

+ 2 - 25
MJRefresh/Custom/Header/MJRefreshNormalHeader.m

@@ -55,29 +55,6 @@ - (void)prepare
     self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
 }
 
-- (CGFloat)stringWidth:(UILabel *)_label
-{
-    CGFloat stringWidth = 0;
-    CGSize size = CGSizeMake(self.mj_w, self.mj_h);
-    if (_label.text.length > 0) {
-#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
-        stringWidth =[_label.text
-                      boundingRectWithSize:size
-                      options:NSStringDrawingUsesLineFragmentOrigin
-                      attributes:@{NSFontAttributeName:_label.font}
-                      context:nil].size.width;
-#else
-        
-        stringWidth = [_label.text sizeWithFont:_label.font
-                              constrainedToSize:size
-                                  lineBreakMode:NSLineBreakByCharWrapping].width;
-#endif
-    }
-    
-    
-    return stringWidth;
-}
-
 - (void)placeSubviews
 {
     [super placeSubviews];
@@ -86,10 +63,10 @@ - (void)placeSubviews
     CGFloat arrowCenterX = self.mj_w * 0.5;
     if (!self.stateLabel.hidden) {
         CGFloat offset = 20;
-        CGFloat stateWidth = [self stringWidth:self.stateLabel];
+        CGFloat stateWidth = self.stateLabel.mj_textWith;
         CGFloat timeWidth = 0.0;
         if (!self.lastUpdatedTimeLabel.hidden) {
-            timeWidth = [self stringWidth:self.lastUpdatedTimeLabel];
+            timeWidth = self.lastUpdatedTimeLabel.mj_textWith;
         }
         CGFloat textWidth = MAX(stateWidth, timeWidth);
         arrowCenterX -= textWidth / 2 + offset;