我有一个子视图并添加了一个按钮。我希望将此按钮添加在该视图的中心位置。我使用Autolayout,因此需要通过编程设置此按钮的约束。
我尝试了这个代码,但播放按钮不在中心位置。
我有一个子视图并添加了一个按钮。我希望将此按钮添加在该视图的中心位置。我使用Autolayout,因此需要通过编程设置此按钮的约束。
[self.moviePlayer.view addSubview:self.playbtn];
self.playbtn.translatesAutoresizingMaskIntoConstraints = NO;
[self.moviePlayer.view addConstraint:[NSLayoutConstraint constraintWithItem:self.playbtn attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual
toItem:self.moviePlayer.view attribute:NSLayoutAttributeCenterX multiplier:0.667 constant:0]];
请帮我纠正它。提前致谢。