gpt4 book ai didi

iphone - 如何为 UIBarButtonItem 设置动画

转载 作者:搜寻专家 更新时间:2023-10-30 20:11:23 25 4
gpt4 key购买 nike

我想像 TheElements 示例项目那样为 UIBarButtonItem 设置动画。我很确定我必须使用 customView 属性,但我不想使用图像来执行此操作,因为我需要使用一些本地化字符串(多语言)更改标题.那么是否可以创建一个看起来像 UIBarButtonItemUIButton

最佳答案

这是代码。

NSArray *images = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image0.png"],
[UIImage imageNamed:@"image1.png"],
nil];

imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.png"]];
imageView.animationImages = images;

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = self.imageView.bounds;
[button addSubview:self.imageView];
[button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem * barButton = [[[UIBarButtonItem alloc] initWithCustomView: button] autorelease];

一些注意事项:

UIButton 的面积为零,因为它在初始化时没有设置边界,因此边界是用 UIImageView 的边界初始化的(它有自己的边界从图像初始化)。

UIButton 处理触摸事件的 Action /目标。 UIBarButtonItem 的操作/目标未设置。

动画:

[imageView startAnimating];

关于iphone - 如何为 UIBarButtonItem 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7514373/

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