gpt4 book ai didi

iOS自定义右侧导航栏

转载 作者:可可西里 更新时间:2023-11-01 05:05:43 24 4
gpt4 key购买 nike

我正在尝试为我的导航 Controller 中的右侧栏项目设置图像,但 iOS 6 一直显示黑光。我已经尝试了一些来自堆栈溢出的解决方案,但无法让它工作。我目前的代码是这样的:

UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gear"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(someMethod)];
[rightItem setImageInsets:UIEdgeInsetsMake(5, 5, 5, 5)];

[[self navigationItem] setRightBarButtonItem:rightItem];

在 iOS7 中是这样的,这正是我想要的: What I want这是它在 iOS6 中的样子 What I currently have

最佳答案

试试这个:

UIImage *faceImage = [UIImage imageNamed:@"gear.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 10, 0, faceImage.size.width, faceImage.size.height );//set bound as per you want
[face addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
[face setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:face];
self.navigationItem.rightBarButtonItem = backButton;

希望对你有帮助。

关于iOS自定义右侧导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758247/

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