ios 轮播图

XMRotationChartView

使用方式 #import “XMRotationChartView.h”

继承XMRotationChartViewDelegate

@interface UIViewController ()<XMRotationChartViewDelegate>

///轮播图片地址集合
@property (nonatomic,strong) NSMutableArray<NSString *> *imageUrl;

@end
///初始化轮播图
	XMRotationChartView *view = [[XMRotationChartView alloc] initWithFrame:CGRectMake(400, 	300, 300, 300)];
    ///轮播图片地址集合
	self.imageUrl = [@[@"img1.png",@"img2.png",@"img3.png"] mutableCopy];
	///设置代理
	view.delegate = self;

	///设置自动滑动方向(默认左滑动,支持动态改变方向)
	[view setRotationChartDirection:XMRotationChartDirectionLeft];
	///添加到本地
	[self.view addSubview:view];

代理方法(必须重写的)



///轮播图数量
- (NSInteger)rotationChartCount:(XMRotationChartView *)RotationChart{
    
    return self.imageUrl.count;
    
}

///初始化轮播图片
- (UIImageView *)rotationChartAtIndex:(XMRotationChartView *)RotationChart atIndex:(NSInteger)index{
    
    UIImageView *imageView =[[UIImageView alloc] init];
    
    [imageView setImage:[UIImage imageNamed:[self.imageUrl objectAtIndex:index]]];
    
    [imageView setContentMode:UIViewContentModeScaleAspectFit];
    
    return imageView;
    
}


代理方法(扩展功能)

///轮播图是否自动轮播(默认不自动轮播)
- (BOOL)isAutoCarousel:(XMRotationChartView *)RotationChart{
    
    return YES;
    
}

///切换图片时的速度(默认0.5秒完成切图)
- (NSTimeInterval)rotationChartSpeed:(XMRotationChartView *)RotationChart{

    return 0.5;
    
}

///轮播图速度(默认两秒切一次图片)
- (NSTimeInterval)IntervalInSeconds:(XMRotationChartView *)RotationChart{
    
    return 2.0;
    
}

///轮播图下边的定位图片的点的颜色(默认为红色)
- (UIColor *) rotationChartTintColor:(XMRotationChartView *)RotationChart{
    
    return [UIColor redColor];
    
}

///(回调方法)返回当前轮播图下标(自动滑动或手指滑动都会回调),点击轮播图不会回调
- (void)rotationChartCurrentIndex:(XMRotationChartView *)RotationChart currentIndex:(NSInteger)index{
    
    NSLog(@"当前下标:%ld",index);
    
}

///点击轮播图回调方法
- (void)didSelectedRotationChartCurrentIndex:(XMRotationChartView *)RotationChart currentIndex:(NSInteger)index{
    
    NSLog(@"点击选择当前下标:%ld",index);
}



发布了34 篇原创文章 · 获赞 30 · 访问量 8647

猜你喜欢

转载自blog.csdn.net/qq_41586150/article/details/104386400