ios VFL 简单例子 ParseSWTableViewCell 想要修改 上下按钮的边距

今天  在使用 ParseSWTableViewCell 想要修改 上下按钮的边距

 if (!precedingView)
            {
                // First button; pin it to the left edge.
                [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[button]"
                                                                             options:0L
                                                                             metrics:nil
                                                                               views:NSDictionaryOfVariableBindings(button)]];
                //增加第一个按钮上下位置
                [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[button]-5-|"
                                                                             options:0L
                                                                             metrics:nil
                                                                               views:NSDictionaryOfVariableBindings(button)]];
            }
            else
            {
                // Subsequent button; pin it to the right edge of the preceding one, with equal width.
                [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[precedingView][button(==precedingView)]"
                                                                             options:NSLayoutFormatAlignAllTop
                                                                             metrics:nil
                                                                               views:NSDictionaryOfVariableBindings(precedingView, button)]];
                //增加 上下位置一致的约束
                [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[precedingView][button(==precedingView)]"
                                                                             options:NSLayoutFormatAlignAllBottom
                                                                             metrics:nil
                                                                               views:NSDictionaryOfVariableBindings(precedingView, button)]];


借鉴 黑马 VFL代码

//
//  ViewController.m
//  06-VFL添加约束
//
//  Created by apple on 14/11/4.
//  Copyright (c) 2014年 heima. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 1.添加两个控件到父控件上
    // 1.1添加蓝色View
    UIView *blueView = [[UIView alloc] init];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    
    // 1.1添加红色View
    UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    
    
    // 2.禁用auturezing
    blueView.translatesAutoresizingMaskIntoConstraints = NO;
    redView.translatesAutoresizingMaskIntoConstraints = NO;
    
    // 3.添加约束
    /*
     lFormat : VFL语句
     options: 对齐方式
     metrics: VFL语句中用到的变量值
     views: VFL语句中用到的控件
     */
    // 设置蓝色View距离左边和右边有20的的间距  X 和 宽度
//    NSArray *blueViewH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[blueView]-20-|" options:0 metrics:nil views:@{@"blueView" : blueView}];
    int margin = 20;
    NSArray *blueViewH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-margin-[blueView]-margin-|" options:0 metrics:@{@"margin": @(margin)} views:@{@"blueView" : blueView}];
    [self.view addConstraints:blueViewH];
    
    // 设置蓝色View距离顶部有20的间距, 并且高度等于50   Y 和高度
    // 设置红色View距离蓝色底部有20的间距, 并且红色View的高度等于蓝色View的高度 Y 和高度
    // 并且设置红色和蓝色右对齐
    NSArray *blueViewV = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[blueView(50)]-20-[redView(==blueView)]" options:NSLayoutFormatAlignAllRight metrics:nil views:@{@"blueView" : blueView, @"redView": redView}];
    [self.view addConstraints:blueViewV];
    
    // 注意: 在VFL语句中, 是不支持乘除法
//    NSArray *redVeiwH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[redView(==blueView )]" options:0 metrics:nil views:@{@"blueView" : blueView, @"redView": redView}];
//    [self.view addConstraints:redVeiwH];
    
    NSLayoutConstraint *redVeiwW = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0];
    [self.view addConstraint:redVeiwW];
}


@end


你可能感兴趣的:(ios VFL 简单例子 ParseSWTableViewCell 想要修改 上下按钮的边距)