ios - UIToolbar - 添加等宽按钮没有间隙
<p><p>我有 UIToolbar,我想给它添加大小相同的 UIButtons。
目前,我有:</p>
<pre><code>CGFloat width = self.toolbarMapMenu.frame.size.width / 4.0;
CGFloat height = self.toolbarMapMenu.frame.size.height;
btn0 = ;
btn1 = ;
btn2 = ;
btn3 = ;
UIBarButtonItem *it0 = [ initWithCustomView:btn0];
UIBarButtonItem *it1 = [ initWithCustomView:btn1];
UIBarButtonItem *it2 = [ initWithCustomView:btn2];
UIBarButtonItem *it3 = [ initWithCustomView:btn3];
[self.toolbarMapMenu setItems:[NSArray arrayWithObjects:
it0,it1,it2,it3,
nil]
];
</code></pre>
<p>还有其他地方</p>
<pre><code>-(UIButton *)createMenuButton: (NSString *)name width:(CGFloat) w height:(CGFloat) h
{
UIButton *btn = ;
btn.tintColor = ;
forState:UIControlStateNormal];
[ setActive:true];
[ setActive:true];
btn.translatesAutoresizingMaskIntoConstraints = false;
return btn;
}
</code></pre>
<p>但是,当我添加这些按钮时,它们的大小相同,但在第一个/最后一个按钮之前和之后有一个间隙:</p>
<p>类似这样的东西(UIToolbar):</p>
<pre><code>(<gap> btn0 btn1 btn2 btn3 <gap>)
</code></pre>
<p>如何消除这个间隙并在工具栏MapMenu 的开头添加按钮?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试在每个项目之间添加灵活的空间,它可能会解决您的问题并提供一致的 View 。 </p>
<pre><code>// Flexible Space
UIBarButtonItem *flexibleItem = [ initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.toolbarMapMenu setItems:[NSArray arrayWithObjects:
it0, flexibleItem,
it1, flexibleItem,
it2, flexibleItem,
it3,
nil]];
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIToolbar - 添加等宽按钮没有间隙,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/50047323/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/50047323/
</a>
</p>
页:
[1]