我想在我的项目中使用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
答案 0 :(得分:1)
我几天前探索过它,因为我记得这部分是一个IBOutlet连接到一个视图,其类从Interface builder设置为iCarousel
。
@property (weak, nonatomic) IBOutlet iCarousel *carousel;
此外,代表们也与IB有联系。
修改强>
查看代码viewDidLoad
:
您还没有初始化_carousel
对象,应该通过IB添加它。看看我附上的图片。
<强> IMAGE1:强>
<强>图像2:强>
<强>图像3:强>
另外,请查看随库提供的示例。
希望它有所帮助!