Browse Source

Expose a top layout guide in the argument input view super class.

The top layout guide is the bottom of the title + padding if we’re showing a title. This way we don’t have to duplicate the logic in the layoutSubviews of every subclass.
Ryan Olson 12 years ago
parent
commit
9a1fa91893

+ 1 - 6
Classes/Editing/Argument Input Views/FLEXArgumentInputSwitchView.m

@@ -65,12 +65,7 @@
 {
     [super layoutSubviews];
     
-    CGFloat originY = 0;
-    if (self.showsTitle) {
-        originY = CGRectGetMaxY(self.titleLabel.frame) + [[self class] titleBottomPadding];
-    }
-    
-    self.inputSwitch.frame = CGRectMake(0, originY, self.inputSwitch.frame.size.width, self.inputSwitch.frame.size.height);
+    self.inputSwitch.frame = CGRectMake(0, self.topInputFieldVerticalLayoutGuide, self.inputSwitch.frame.size.width, self.inputSwitch.frame.size.height);
 }
 
 - (CGSize)sizeThatFits:(CGSize)size

+ 1 - 5
Classes/Editing/Argument Input Views/FLEXArgumentInputTextView.m

@@ -50,11 +50,7 @@
 {
     [super layoutSubviews];
     
-    CGFloat originY = 0;
-    if (self.showsTitle) {
-        originY = CGRectGetMaxY(self.titleLabel.frame) + [[self class] titleBottomPadding];
-    }
-    self.inputTextView.frame = CGRectMake(0, originY, self.bounds.size.width, [self inputTextViewHeight]);
+    self.inputTextView.frame = CGRectMake(0, self.topInputFieldVerticalLayoutGuide, self.bounds.size.width, [self inputTextViewHeight]);
 }
 
 - (NSUInteger)numberOfInputLines

+ 1 - 2
Classes/Editing/Argument Input Views/FLEXArgumentInputView.h

@@ -47,9 +47,8 @@ typedef NS_ENUM(NSUInteger, FLEXArgumentInputViewSize) {
 // For subclass eyes only
 
 @property (nonatomic, strong, readonly) UILabel *titleLabel;
-@property (nonatomic, readonly) BOOL showsTitle;
-+ (CGFloat)titleBottomPadding;
 @property (nonatomic, strong, readonly) NSString *typeEncoding;
+@property (nonatomic, readonly) CGFloat topInputFieldVerticalLayoutGuide;
 
 @end
 

+ 10 - 0
Classes/Editing/Argument Input Views/FLEXArgumentInputView.m

@@ -65,6 +65,16 @@
     return [self.title length] > 0;
 }
 
+- (CGFloat)topInputFieldVerticalLayoutGuide
+{
+    CGFloat verticalLayoutGuide = 0;
+    if (self.showsTitle) {
+        CGFloat titleHeight = ceil([self.title sizeWithFont:[[self class] titleFont] constrainedToSize:self.bounds.size].height);
+        verticalLayoutGuide = titleHeight + [[self class] titleBottomPadding];
+    }
+    return verticalLayoutGuide;
+}
+
 
 #pragma mark - Subclasses Can Override