我有三个UIButtons
和一个支架UIView
我想要我的三个 UIButton
在 UIView
内垂直居中并且我希望它们在水平方向上均匀分布
float ycentre = CGRectGetMidY(self.buttonHolderView.bounds);
float xposition = (self.buttonHolderView.frame.size.width - 135.0f)/4.0f;
self.button1 = [[UIButton alloc]initWithFrame:CGRectMake(xposition,0, 45, 30)];
self.button1.center = CGPointMake(self.button1.frame.origin.x, ycentre);
self.button2 = [[UIButton alloc]initWithFrame:CGRectMake((xposition*2)+45,0, 45, 30)];
self.button2.center = CGPointMake(self.button2.frame.origin.x, ycentre);
self.button3 = [[UIButton alloc]initWithFrame:CGRectMake((xposition*3)+90,0, 45, 30)];
self.button3.center = CGPointMake(self.button3.frame.origin.x, ycentre);
[self.button3 addTarget:self action:@selector(ShareButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.buttonHolderView addSubview:self.button1];
[self.buttonHolderView addSubview:self.button2];
[self.buttonHolderView addSubview:self.button3];
每个按钮的高度为 30 和宽度为 45,但我的代码没有平均分配它们,这是怎么回事?
最佳答案
将它们放在 UIStackView
中。它使 View 之间的间隔非常容易。
关于ios - 水平均匀分布三个按钮ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44344503/