使用定制视图从笔尖创建具有倒轮类型iCarousel
@IBOutlet weak var viewCarousel: iCarousel!
override func viewDidLoad() {
super.viewDidLoad()
viewCarousel.type = .invertedWheel
viewCarousel.isVertical = true
viewCarousel.delegate = self
viewCarousel.dataSource = self
}
iCarousel的DataSource
func numberOfItems(in carousel: iCarousel) -> Int {
return 25
}
func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
// use a custom view from nib
let view = Bundle.main.loadNibNamed("CarouselReuseView", owner: self, options: nil)![0] as! CarouselReuseView
view.frame.size = CGSize(width: self.view.frame.size.width/2, height: 83.0)
view.backgroundColor = UIColor.lightGray
let friend = friendList[index] as friend
view.lblName.text = friend.fullName
let url = friend.photo
let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: {data, response, error in
if error == nil {
DispatchQueue.main.async {
view.imageView.image = UIImage(data: data!)
view.imageView.layer.cornerRadius = view.imageView.frame.size.width/2
view.imageView.layer.masksToBounds = true
}
}
})
task.resume()
return view
}
}
ObjectivÇ
@property (weak, nonatomic) IBOutlet iCarousel *carouselView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_carouselView.type = iCarouselTypeInvertedWheel;
_carouselView.vertical = true;
_carouselView.delegate = self;
_carouselView.dataSource = self;
_carouselView.layer.masksToBounds = true;
}
iCarousel的DataSource
-(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return 10;
}
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
CustomView* myViewObject = [[[NSBundle mainBundle] loadNibNamed:@"customView" owner:self options:nil] objectAtIndex:0];
myViewObject.lbl.text = [NSString stringWithFormat:@"%ld",(long)index];
return myViewObject;
}
这里CustomView是我的UIView的子类, “customView” 是的UIView XIB名 我希望这会帮助你
更多信息: - https://github.com/nicklockwood/iCarousel
这你需要哪种解决方案? – KKRocks
详细阐述了这一点:1.我如何从XIB载入不同的视图? 2.如何从故事板查看iCarousel VIEW? – KKRocks
需要在故事板或xib的卡集视图中添加自定义视图。 – BhaviDev