gpt4 book ai didi

ios - iOS6自定义导航栏按钮

转载 作者:可可西里 更新时间:2023-11-01 06:23:17 26 4
gpt4 key购买 nike

更新 - 一种可能的解决方案

根据 Alexander Merchi 在这篇文章 ( UIBarButtonItem Custom view in UINavigationBar ) 中给出的答案,找到了解决方案。但仍然不知道如何正确更改图像的位置。

UIButton *btn =  [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 28.0f, 28.0f)]; // 28 points is the width or height of the button image
[btn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(onClickMenuButton) forControlEvents:UIControlEventTouchUpInside];
btnMenu = [[UIBarButtonItem alloc] initWithCustomView:btn];

enter image description here

原帖

在 iOS 6 中,目标是这样的:

enter image description here

当前结果是这样的:

enter image description here

我的代码是

btnMenu = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(onClickMenuButton)];

button.png 就是这个白色的圆圈,里面是白色的三道杠,背景是透明的。

最佳答案

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 30, 30);
[rightButton setImage:[UIImage imageNamed:@"Button-normal"] forState:UIControlStateNormal];
[rightButton setImage:[UIImage imageNamed:@"logout-hover"] forState:UIControlStateHighlighted];
[rightButton addTarget:self action:@selector(logOut) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.leftBarButtonItem = rightBarButtonItem;

关于ios - iOS6自定义导航栏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20324222/

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