gpt4 book ai didi

objective-c - 如何向 UIBarButtonItem 添加图像?

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

我创建了一个自定义按钮并将其应用于 UIbarbuttonitem。没有错误,但导航栏上没有显示任何内容:(这是我的代码-

    //create a custom button
UIImage *image = [UIImage imageNamed:@"TESTButton.png"];
UIButton *myCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
myCustomButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[myCustomButton setImage:image forState:UIControlStateNormal];
[myCustomButton addTarget:nil action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];


UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myCustomButton];
self.navigationItem.leftBarButtonItem = button;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

[button release];
[myCustomButton release];
[image release];
[navID release];

谁能修复我的代码? :)

最佳答案

来自 the docs:

initWithImage:style:target:action:

试试吧。

关于objective-c - 如何向 UIBarButtonItem 添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6721837/

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