Appdelegate.m
import "AppDelegate.h"
import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];_window.rootViewController = [[ViewController alloc] init];
[_window makeKeyAndVisible];
return YES;
}
ViewController.m
import "ViewController.h"
import "DCPicScrollView.h"
import "DCWebImageManager.h"
@interface ViewController ()
@end
static CGFloat h = 180;
@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];self.view.backgroundColor = [UIColor whiteColor];
[self demo1];
[self demo2];
} -
(void)demo1 {
//網絡加載
NSArray *UrlStringArray = @[@"http://p1.qqyou.com/pic/UploadPic/2013-3/19/2013031923222781617.jpg",
@"http://cdn.duitang.com/uploads/item/201409/27/20140927192649_NxVKT.thumb.700_0.png",
@"http://img4.duitang.com/uploads/item/201409/27/20140927192458_GcRxV.jpeg",
@"http://cdn.duitang.com/uploads/item/201304/20/20130420192413_TeRRP.thumb.700_0.jpeg"];
NSArray *titleArray = [@"午夜寂寞 誰來陪我" componentsSeparatedByString:@"."];
//顯示順序和數組順序一致
//設置圖片url數組,和滾動視圖位置
DCPicScrollView *picView = [DCPicScrollView picScrollViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, h * 2) WithImageUrls:UrlStringArray];
//顯示順序和數組順序一致
//設置標題顯示文本數組
picView.titleData = titleArray;
//占位圖片,你可以在下載圖片失敗處修改占位圖片
picView.placeImage = [UIImage imageNamed:@"place.png"];
//圖片被點擊事件,當前第幾張圖片被點擊了,和數組順序一致
[picView setImageViewDidTapAtIndex:^(NSInteger index) {
printf("第%zd張圖片\n",index);
}];
//default is 2.0f,如果小于0.5不自動播放
picView.AutoScrollDelay = 1.0f;
// picView.textColor = [UIColor redColor];
[self.view addSubview:picView];
//下載失敗重復下載次數,默認不重復,
[[DCWebImageManager shareManager] setDownloadImageRepeatCount:1];
//圖片下載失敗會調用該block(如果設置了重復下載次數,則會在重復下載完后,假如還沒下載成功,就會調用該block)
//error錯誤信息
//url下載失敗的imageurl
[[DCWebImageManager shareManager] setDownLoadImageError:^(NSError *error, NSString *url) {
NSLog(@"%@",error);
}];
}
//本地加載只要放圖片名數組就行了
-(void)demo2 {
NSMutableArray *arr2 = [[NSMutableArray alloc] init];
NSMutableArray *arr3 = [[NSMutableArray alloc] init];
for (int i = 1; i < 8; i++) {
[arr2 addObject:[NSString stringWithFormat:@"%d.jpg",i]];
[arr3 addObject:[NSString stringWithFormat:@"我是第%d張圖片",i]];
};
DCPicScrollView *picView1 = [DCPicScrollView picScrollViewWithFrame:CGRectMake(0,self.view.frame.size.height - h*2,self.view.frame.size.width, h) WithImageUrls:arr2];
picView1.titleData = arr3;
picView1.backgroundColor = [UIColor clearColor];
[picView1 setImageViewDidTapAtIndex:^(NSInteger index) {
printf("你點到我了??index:%zd\n",index);
}];
picView1.AutoScrollDelay = 2.0f;
[self.view addSubview:picView1];
}
@end