可以使用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);
}];
}
答案 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));
}];
}