【发布时间】:2014-04-07 07:04:53
【问题描述】:
我想在我的项目中使用 icarousel。我已经从 github 下载了 icarousel。当我添加 icarousel 时,它没有出现。可能是什么原因?
这是我的代码:
PhotoPreview.h
#import <UIKit/UIKit.h>
#import "iCarousel.h"
@interface PhotoPreview : UIViewController <iCarouselDataSource,iCarouselDelegate>
@property (weak, nonatomic) iCarousel *carousel;
@end
PhotoPreview.m
#import "PhotoPreview.h"
@interface PhotoPreview (){
NSMutableArray *items;
}
@end
@implementation PhotoPreview
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_carousel.type = iCarouselTypeCoverFlow2;
[self.view addSubview:_carousel];
}
-(void)viewWillAppear:(BOOL)animated{
items = [[NSMutableArray alloc] init];
for (int i = 0; i < 100; i++)
{
[items addObject:@(i)];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
NSLog(@"%d",items.count);
return 5;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
}
else
{
label = (UILabel *)[view viewWithTag:1];
}
label.text = @"AAA";
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
if (option == iCarouselOptionSpacing)
{
return value * 1.1f;
}
return value;
}
@end
【问题讨论】:
标签: ios uiviewcontroller uiimageview icarousel