masonry自适应文字大小

//
//  YellowViewController.m
//  MasonryTest
//
//  Created by 舒通 on 2017/1/11.
//  Copyright © 2017年 shutong. All rights reserved.
//

#import <Masonry.h>
#import "YellowViewController.h"
#import "ViewController.h"

@interface YellowViewController ()

@property (nonatomic, strong) UIView *yellowView;
@property (nonatomic, strong) UIView *blueView;
@property (nonatomic, strong) UIView *greenView;
@property (nonatomic, strong) UILabel *textLabel;

@end

@implementation YellowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    [self createView:self.index];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - creat UI
- (void) createView:(NSInteger)index {
    switch (index) {
        case 10:{
//            设置内边距
            [self.yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.view).with.offset(10);
                make.top.equalTo(self.view).with.offset(10);
                make.right.equalTo(self.view).with.offset(-10);
                make.bottom.equalTo(self.view).with.offset(-10);
            }];
        }
            break;
        case 11:{
//            设置内边距
            [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
//                下右不需要写负号,insets方法中已经为我们做了取反的操作了
                make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
            }];
            
            
        }
            break;
        case 12:{
            [self.greenView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self.view);
         // 这里通过mas_equalTo给size设置了基础数据类型的参数,参数为CGSize的结构体
                make.size.mas_equalTo(CGSizeMake(300, 300));
            }];
            
            __weak typeof(self)weakSelf = self;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf.greenView mas_updateConstraints:^(MASConstraintMaker *make) {
                    __strong typeof(weakSelf)blockSelf = weakSelf;
                    make.centerX.equalTo(blockSelf.view).offset(100);
                    make.size.mas_equalTo(CGSizeMake(100, 100));
                }];
            });
            
        }
            break;
        case 13:{
            self.textLabel.text = @"这是测试的字符串。能看到1、2、3个步骤,第一步当然是上传照片了,要上传正面近照哦。上传后,网站会自动识别你的面部,如果觉得识别的不准,你还可以手动修改一下。左边可以看到16项修改参数,最上面是整体修改,你也可以根据自己的意愿单独修改某项,将鼠标放到选项上面,右边的预览图会显示相应的位置。";
            
            [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self.view);
                
//                设置宽度小于等于200
                make.width.lessThanOrEqualTo(@200);
//                设置高度大于等于10
                make.height.greaterThanOrEqualTo(@0);
            }];
            
            UIView *view = [[UIView alloc]init];
            view.backgroundColor = [UIColor redColor];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.textLabel.mas_bottom).offset(10);
                make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 20));
            }];
        }
            break;
            
        case 14:{
            /**
             Masonry为我们提供了三个默认的方法,priorityLow()、priorityMedium()、priorityHigh(),这三个方法内部对应着不同的默认优先级。
             除了这三个方法,我们也可以自己设置优先级的值,可以通过priority()方法来设置。
             
             Masonry也帮我们定义好了一些默认的优先级常量,分别对应着不同的数值,优先级最大数值是1000。
             */
            [self.yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self.view);
                make.width.equalTo(self.view).priorityLow();
                make.width.equalTo(@20).priorityHigh();
                make.height.equalTo(self.view).priority(200);
                make.height.equalTo(@100).priority(1000);
                
            }];
            
        }
            break;
            
        case 15: {
//             设置当前约束值乘以多少,例如这个例子是redView的宽度是self.view宽度的0.2倍
            [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self.view);
                make.height.mas_equalTo(30);
                make.width.mas_equalTo(self.view).multipliedBy(0.5);
            }];
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark - touch Event
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    ViewController *viewVC = [[ViewController alloc]init];
    [self dismissViewControllerAnimated:viewVC completion:^{
        
    }];
}


#pragma mark - setter / getter

- (UIView *)yellowView {
    if (_yellowView == nil) {
        _yellowView = [[UIView alloc]init];
        _yellowView.backgroundColor = [UIColor yellowColor];
        [self.view addSubview:_yellowView];
    }
    return _yellowView;
}
- (UIView *)blueView {
    if (_blueView == nil) {
        _blueView = [[UIView alloc]init];
        _blueView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:_blueView];
    }
    return _blueView;
}
- (UIView *)greenView {
    if (_greenView == nil) {
        _greenView = [[UIView alloc]init];
        _greenView.backgroundColor = [UIColor greenColor];
        [self.view addSubview:_greenView];
    }
    return _greenView;
}
- (UILabel *)textLabel {
    if (_textLabel == nil) {
        _textLabel = [UILabel new];
        _textLabel.font = [UIFont systemFontOfSize:14];
        _textLabel.textColor = [UIColor redColor];
        _textLabel.backgroundColor = [UIColor greenColor];
        _textLabel.numberOfLines = 0;
        [self.view addSubview:_textLabel];
    }
    return _textLabel;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值