gpt4 book ai didi

ios - 如何更改 BarButtonItem 的水平位置

转载 作者:行者123 更新时间:2023-12-01 17:23:05 25 4
gpt4 key购买 nike

我可以使用 setBackgroundVerticalPositionAdjustment 更改自定义栏按钮项的 y,但是如何更改水平位置?

[viewController.navigationItem.rightBarButtonItem setBackgroundVerticalPositionAdjustment:50 forBarMetrics:UIBarMetricsDefault];

最佳答案

您可以使用自定义 View 创建条形按钮,并在该 View 中创建自己的布局。它可以只是简单的 UIButton,你可以在 UIButton 中设置 edgeInsets。

Customization of UINavigationBar and the back button

f.e.

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:[UIImage imageNamed:@"chk_back.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(BackBtn) forControlEvents:UIControlEventTouchUpInside];
UIView *customView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 50, 38)] autorelease];
btn.frame = CGRectMake(10, 3, 30, 32); // where you can set your insets
[customView addSubview:btn];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:customView];

或者你可以在你的酒吧项目之后或之前在酒吧中添加一些固定空间
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[fixedSpace setWidth:20];

关于ios - 如何更改 BarButtonItem 的水平位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19242510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com