gpt4 book ai didi

iphone - 更改 UIBarButton 的图像

转载 作者:行者123 更新时间:2023-12-03 19:37:24 27 4
gpt4 key购买 nike

我的目标是以编程方式更改 UIBarButton(我用作 IBOutlet)的图像。

我在 stackoverflow 上找到了这个解决方案 change-image-of-uibutton-with-other-image 。但这在 iOS 4.2 上不起作用。

任何人都可以帮我解决这个问题吗?西蒙

我尝试过:

UIImage *image = [UIImage imageWithContentsOfFile: 
[[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];
playButton.image = image;
<小时/>
UIImage *image = [UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];UIImage *image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
playButton = [[UIBarButtonItem alloc]initWithCustomView:someButton];

[someButton release];

最佳答案

如果您想将图像放入按钮,请使用以下代码。

UIImage *image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"play" ofType:@"png"]];

CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);

UIButton* someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
playButton = [[UIBarButtonItem alloc]initWithCustomView:someButton];

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

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