Przeglądaj źródła

VLCStatusLabel: adjust label size in sizeToFit instead of manipulating frame directly

Gleb Pinigin 11 lat temu
rodzic
commit
7ab453c43a
1 zmienionych plików z 9 dodań i 1 usunięć
  1. 9 1
      Sources/VLCStatusLabel.m

+ 9 - 1
Sources/VLCStatusLabel.m

@@ -55,7 +55,6 @@
     [self sizeToFit];
     CGRect selfFrame = self.frame;
     CGRect parentFrame = [self superview].bounds;
-    selfFrame.size.width += 15.; // take extra width into account for our custom drawing
     selfFrame.origin.x = (parentFrame.size.width - selfFrame.size.width) / 2.;
     [self setFrame:selfFrame];
 
@@ -100,6 +99,15 @@
     [UIView animateWithDuration:duration animations:animationBlock completion:completionBlock];
 }
 
+#pragma mark - sizing
+
+- (CGSize)sizeThatFits:(CGSize)size
+{
+    CGSize textSize = [self.text sizeWithFont:self.font];
+    textSize.width += 16.f; // take extra width into account for our custom drawing
+    return textSize;
+}
+
 #pragma mark -
 
 - (void)drawRect:(CGRect)rect