MST
星途 面试题库

面试题:Objective-C中Masonry自动布局框架基础使用

在Objective-C项目中,假设有一个视图`UIView`对象`viewA`,要求使用Masonry框架将其约束在父视图的中心位置,且宽高都为200,请写出对应的代码实现。
40.0万 热度难度
编程语言Objective-C

知识考点

AI 面试

面试题答案

一键面试
#import "Masonry.h"

// 假设在某个视图控制器中
@interface ViewController ()
@property (nonatomic, strong) UIView *viewA;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewA = [[UIView alloc] init];
    [self.view addSubview:self.viewA];
    
    [self.viewA mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.width.height.equalTo(@200);
    }];
}

@end