我可以更改导航栏项的位置吗? [英] Can I change the position of navigationbar item?

查看:118
本文介绍了我可以更改导航栏项的位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是快照:

Here is the snapshot:

代码在这里:

UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0.0f, 0.0f, 46.0f, 32.0f);
[leftButton setBackgroundImage:[UIImage imageNamed:@"navi_register_up.png"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(doRegister) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
self.navigationItem.leftBarButtonItem = leftBarItem;
[leftBarItem release];

有没有办法将按钮移动到某个px?
谢谢:)

Is there any way to move the button up some px? Thank you:)

推荐答案

你需要创建一个 UIBarButtonItem 系统项 UIBarButtonSystemItemFixedSpace ,-5宽度将删除 5 px 填充。然后设置 leftBarButtonItems 同时使用固定空间项目和后栏项目 -

You need to create a UIBarButtonItem with system item UIBarButtonSystemItemFixedSpace with -5 width which will remove 5 px padding. Then set leftBarButtonItems with both fixed space item and your back bar item like this -

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[negativeSpacer setWidth:-5];

self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,leftBarItem,nil];

这篇关于我可以更改导航栏项的位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆