gpt4 book ai didi

ios - 使用obj-c的UINavigationController居中按钮

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

我正在尝试在导航栏标题中添加居中按钮,但对如何操作却感到困惑

- (void)viewDidLoad {
[super viewDidLoad];
UIImage *meImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/me.png", kSelfBundlePath]];
UIBarButtonItem *meButton = [[UIBarButtonItem alloc] initWithImage:meImage style:UIBarButtonItemStylePlain target:self action:@selector(twitterButton)];


[self.titleView //i read this can be used to like set it but i havent been able to figure it out

帮助将不胜感激,很新

最佳答案

检查此代码

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
container.backgroundColor = [UIColor clearColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 44, 44)];
[btn setBackgroundImage:[UIImage imageNamed:@"button0.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[btn setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];

//add your spacer images and button1 and button2...

self.navigationItem.titleView = container;

关于ios - 使用obj-c的UINavigationController居中按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42713052/

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