【发布时间】:2012-11-21 04:44:10
【问题描述】:
我有 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 的大小但仍然无法正常工作。 谢谢...
【问题讨论】:
-
Hey Dave 尝试通过 xib 文件调整包含 iCarousal 的 UIView,增加或减少其宽度/高度,最终轮播将居中....试试这个...
-
@Gill 我想他已经在问题的最后一行提到了这一点。
-
@Robin 是的,但我已经实现了同样的事情,需要一些尝试和尝试才能把它放在中心......
-
@Gill,感谢您的提醒,让我再试一次。实际上我希望它在编码中。
-
在我的例子中,我忘记设置自动调整大小或自动布局约束,所以视图稍微偏离了边缘。