ios - 在 iOS 8.2 上更改 UIBarButtonItem 的垂直位置
<p><p>这是我的导航栏</p>
<p> <img src="/image/c4NLs.png" alt="Image link"/> </p>
<p>我在更改导航栏上设置 <code>UIBarButtonItem</code> 的垂直位置时遇到问题。我想将按钮项“设置”向下移动</p>
<p>这是我的代码</p>
<pre><code> UIBarButtonItem *settingsItem = [ initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:nil];
self.navItem.rightBarButtonItem = settingsItem;
[ setTitlePositionAdjustment:UIOffsetMake(0,-10) forBarMetrics:UIBarMetricsDefault];
</code></pre>
<p>我一次又一次地尝试过。好像不行</p>
<p>谁能建议我如何将“设置”按钮项向下移动? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以轻松地将自定义按钮添加到您的 NavigationBarItem,这是方法,</p>
<pre><code> UIButton *button = ; //create custom Button
;
];
forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 20); //Button frame
; //Add action method to the button here
UIView *backButtonView = [ initWithFrame:CGRectMake(0, 0, 63, 33)];
backButtonView.bounds = CGRectOffset(backButtonView.bounds, -14, -7);
;
UIBarButtonItem *barBtnItem = [initWithCustomView: backButtonView]; //set button as UIBarButtonItem
self.navigationItem.rightBarButtonItem = barBtnItem; //set barBtnItem to rightBarButtonItem
</code></pre>
<p>通过更改 <code>backButtonView.bounds</code> 值,您可以更改 Button 的来源</p></p>
<p style="font-size: 20px;">关于ios - 在 iOS 8.2 上更改 UIBarButtonItem 的垂直位置,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29060482/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29060482/
</a>
</p>
页:
[1]