我可以更改导航栏项的位置吗?

编程入门 行业动态 更新时间:2024-10-27 14:20:49
本文介绍了我可以更改导航栏项的位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是快照:

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];

更多推荐

我可以更改导航栏项的位置吗?

本文发布于:2023-07-20 05:09:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1164507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!