以编程方式和Storyboard约束

时间:2015-05-30 23:29:32

标签: objective-c xcode-storyboard masonry-ios-osx

可以使用Storyboard以编程方式设置约束吗?我正在使用此https://github.com/raphaelschaad/RSPlayPauseButton以及约束https://github.com/SnapKit/Masonry。但是我没有正确显示:
Bad Good

左侧图像显示不正确,无法点击(按钮)。

相关代码:

- (void)viewDidLoad {

    [super viewDidLoad];

    _playPauseButton = [[RSPlayPauseButton alloc] init];
    _playPauseButton.tintColor = [UIColor blackColor];
    [_playPauseButton addTarget:self action:@selector(playPauseButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_playPauseButton];
}

- (void)viewDidLayoutSubviews
{
    [self.playPauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.view).with.offset(10);
        }];
}

1 个答案:

答案 0 :(得分:1)

您需要为playPauseButton添加宽度/高度限制,请尝试:

- (void)viewDidLoad {
    [super viewDidLoad];

    _playPauseButton = [[RSPlayPauseButton alloc] init];
    _playPauseButton.tintColor = [UIColor blackColor];
    [_playPauseButton addTarget:self action:@selector(playPauseButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_playPauseButton];

    [playPauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view).with.offset(10);
        make.width.equalTo(@(50));
        make.height.equalTo(@(50));
    }];
}