技术文章分类(180)

技术随笔(11)

MartinLiPageScrollView广告栏实现

功能:

图片循环滚动,自动滚动,点击事件。如果要加载网络图片自然也是很容易的事情。

github 下载demo:https://github.com/MartinLi841538513/MartinDemos (一切以demo为准)

MartinLiPageScrollView集成大法:

一,引入MartinLiPageScrollView.h .m文件,第三方库SDWebImage(这里是为了可以加载网络图片),在xib中添加UIScrollview,这里主要注意几点:

1,使用NSLayoutConstraint布局UIScrollView 的top ,left,right,height

2,UIScrollview继承MartinLiPageScrollView,把UIScrollview以及他的布局height连接Controller。引入.h文件,并实现MartinLiPageScrollViewDelegate协议

3,在.m文件中添加以下代码,即可实现效果

#import "ScrollPageViewController.h"

@interface ScrollPageViewController ()
@end

@implementation ScrollPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //设置图片url
    self.pageView.imageType = UIImageUrlType;//传入image的方式(必填)
    self.pageView.imgUrls = [NSArray arrayWithObjects:@"testImg1.png",@"testImg1.png",@"http://gtms04.alicdn.com/tps/i4/TB10SpoGFXXXXXbapXXvKyzTVXX-520-280.jpg", @"http://gtms04.alicdn.com/tps/i4/TB10SpoGFXXXXXbapXXvKyzTVXX-520-280.jpg",nil];//(必填)
    self.pageView.titles = [NSArray arrayWithObjects:@"1",@"2",@"3", @"4",nil];//设置图片对应的title(可选)
    self.pageView.martinLiPageScrollViewDelegate = self;//(必填)
    self.pageView.height = self.height.constant;//(必填)
    self.pageView.timeInterval = 3;//默认自动滚动图片时间为2秒(可选)
    self.pageView.isAutoScroll = YES;//默认是NO(可选)
    self.pageView.titleIsHidden = NO;//默认为NO(可选)
    self.pageView.pageViewType = MLPageScrollViewAdvertiseMode;//默认是广告模式(可选)
    [self.pageView updatePageViewInFatherController:self];//(必填)//位置置于后面
    self.pageView.defaultLocationIndex = 2;//这一步必须放在最后。(可选)

}

#pragma MartinLiPageScrollViewDelegate
-(void)imgViewDidTouchActionAtIndex:(NSInteger)index inArray:(NSArray *)array{
    NSLog(@"%d",index);
}
@end

 

posted @ 2014-11-24 21:49  坤哥MartinLi  阅读(389)  评论(0编辑  收藏  举报