gpt4 book ai didi

iphone - 更改 UIBarButtonItem 的图像时遇到问题

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

我正在尝试各种方法来更改 UIBarButtonItem 的图像,一旦它被按下,没有任何运气。

// bookmarkButton is a property linked up in IB
-(IBAction)bookmarkButtonTapped:(id)sender
{
NSLog(@"this action triggers");
// attempt 1
UIBarButtonItem* aBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bookmarkdelete.png"] style:UIBarButtonItemStylePlain target:self action:@selector(bookmarkButtonTapped:)];
bookmarkButton = aBarButtonItem;
[aBarButtonItem release];

// attempt 2
bookmarkButton.image = [UIImage imageNamed:@"bookmarkdelete.png"];
}

还有其他方法吗?

最佳答案

工具栏包含一个数组 - items - 作为属性。因此,在将工具栏设置为 IBOutlet 属性后,我不得不将一个新按钮插入到该数组中……像这样:

NSMutableArray *items = [[NSMutableArray alloc] initWithArray:self.toolBar.items];
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"newButton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonTapped:)];
[items replaceObjectAtIndex:0 withObject:newButton];
self.toolBar.items = items;
[newButton release];
[items release];

关于iphone - 更改 UIBarButtonItem 的图像时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4246554/

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