gpt4 book ai didi

iphone - 如何使 iCarousel View 居中

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:12:53 25 4
gpt4 key购买 nike

我有 6 个按钮,我想使用 iCarousel 制作动画,代码如下

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIButton *button = (UIButton *)view;
if (button == nil)
{
self.icon = [NSMutableArray arrayWithObjects:@"icon-02.png",@"icon-03.png",@"icon-04.png",@"icon-05.png",@"icon-06.png",@"icon-07.png",nil];


//no button available to recycle, so create new one
UIImage *image = [UIImage imageNamed:[icon objectAtIndex:index]];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 130.0f, 130.0f);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateNormal];
//button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
//[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}



return button;
}

但是按钮不在中心,现在有没有人热衷于在中心制作旋转木马,我已经调整了 uiview 的大小但仍然无法正常工作。谢谢...

最佳答案

默认情况下轮播和轮播项目​​应该居中(它们在 iCarousel 附带的示例项目中,没有做任何特别的事情)。无需调整 Nib 中旋转木马的位置(除非它没有明显居中)。如果这没有按预期工作,您可能发现了一个错误 - 您可以在项目的 github 页面上提出问题吗?

无关:你的按钮回收逻辑是完全错误的,只是巧合。除其他外,您要重新创建图标数组 6 次。

创建按钮的正确方法是这样的:

- (void)viewDidLoad
{
[super viewDidLoad];

//set up icons array
self.icon = [NSMutableArray arrayWithObjects:@"icon-02.png",@"icon-03.png",@"icon-04.png",@"icon-05.png",@"icon-06.png",@"icon-07.png",nil];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIButton *button = (UIButton *)view;
if (button == nil)
{
//*************************************************
//do setup that is the same for every button here
//*************************************************

button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 130.0f, 130.0f);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
//[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}

//*************************************************
//do setup that is different depending on index here
//*************************************************

UIImage *image = [UIImage imageNamed:[icon objectAtIndex:index]];
[button setBackgroundImage:image forState:UIControlStateNormal];

return button;
}

关于iphone - 如何使 iCarousel View 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13486473/

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