Prechádzať zdrojové kódy

Added support and tests for leading and trailing insets.

Monte Hurd 10 rokov pred
rodič
commit
4ce6a4b367

+ 2 - 0
Masonry/MASViewConstraint.m

@@ -235,6 +235,7 @@ static char kInstalledConstraintsKey;
     NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
     NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
     switch (layoutAttribute) {
     switch (layoutAttribute) {
         case NSLayoutAttributeLeft:
         case NSLayoutAttributeLeft:
+        case NSLayoutAttributeLeading:
             self.layoutConstant = insets.left;
             self.layoutConstant = insets.left;
             break;
             break;
         case NSLayoutAttributeTop:
         case NSLayoutAttributeTop:
@@ -244,6 +245,7 @@ static char kInstalledConstraintsKey;
             self.layoutConstant = -insets.bottom;
             self.layoutConstant = -insets.bottom;
             break;
             break;
         case NSLayoutAttributeRight:
         case NSLayoutAttributeRight:
+        case NSLayoutAttributeTrailing:
             self.layoutConstant = -insets.right;
             self.layoutConstant = -insets.right;
             break;
             break;
         default:
         default:

+ 8 - 0
Tests/Specs/MASViewConstraintSpec.m

@@ -168,6 +168,10 @@ SpecBegin(MASViewConstraint) {
     left.equalTo(value);
     left.equalTo(value);
     expect(left.layoutConstant).to.equal(20);
     expect(left.layoutConstant).to.equal(20);
 
 
+    MASViewConstraint *leading = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_leading];
+    leading.equalTo(value);
+    expect(leading.layoutConstant).to.equal(20);
+
     MASViewConstraint *bottom = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_bottom];
     MASViewConstraint *bottom = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_bottom];
     bottom.equalTo(value);
     bottom.equalTo(value);
     expect(bottom.layoutConstant).to.equal(-30);
     expect(bottom.layoutConstant).to.equal(-30);
@@ -175,6 +179,10 @@ SpecBegin(MASViewConstraint) {
     MASViewConstraint *right = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_right];
     MASViewConstraint *right = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_right];
     right.equalTo(value);
     right.equalTo(value);
     expect(right.layoutConstant).to.equal(-40);
     expect(right.layoutConstant).to.equal(-40);
+
+    MASViewConstraint *trailing = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_trailing];
+    trailing.equalTo(value);
+    expect(trailing.layoutConstant).to.equal(-40);
     
     
     MASViewConstraint *centerX = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_centerX];
     MASViewConstraint *centerX = [[MASViewConstraint alloc] initWithFirstViewAttribute:otherView.mas_centerX];
     centerX.equalTo(value);
     centerX.equalTo(value);