0

是否可以在使用 Storyboard 时以编程方式设置约束?我正在使用这个https://github.com/raphaelschaad/RSPlayPauseButton以及这个作为约束https://github.com/SnapKit/Masonry。但是我他们没有正确显示:
坏的 好的

左侧的图像未正确显示,并且不可点击(它是一个按钮)。

相关代码:

- (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);
        }];
}
4

1 回答 1

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));
    }];
}
于 2015-05-31T00:56:18.000 回答