Commit 0196d7d31130b8ba1a8e242274816f9008433385
1 parent
ae9bbd6b
no message
Showing
18 changed files
with
2185 additions
and
2 deletions
CNLiveScioLive.xcodeproj/project.pbxproj
| ... | ... | @@ -672,6 +672,13 @@ |
| 672 | 672 | 08C090BF215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; }; |
| 673 | 673 | 08C090C0215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; }; |
| 674 | 674 | 08C090C1215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */; }; |
| 675 | + 08C721B924CAC9B700970100 /* SDCycleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AD24CAC9B700970100 /* SDCycleScrollView.m */; }; | |
| 676 | + 08C721BA24CAC9B700970100 /* UIView+SDExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AE24CAC9B700970100 /* UIView+SDExtension.m */; }; | |
| 677 | + 08C721BB24CAC9B700970100 /* SDCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721AF24CAC9B700970100 /* SDCollectionViewCell.m */; }; | |
| 678 | + 08C721BC24CAC9B700970100 /* TADotView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721B224CAC9B700970100 /* TADotView.m */; }; | |
| 679 | + 08C721BD24CAC9B700970100 /* TAPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721B324CAC9B700970100 /* TAPageControl.m */; }; | |
| 680 | + 08C721BE24CAC9B700970100 /* TAAnimatedDotView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721B424CAC9B700970100 /* TAAnimatedDotView.m */; }; | |
| 681 | + 08C721BF24CAC9B700970100 /* TAAbstractDotView.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C721B524CAC9B700970100 /* TAAbstractDotView.m */; }; | |
| 675 | 682 | 08E7998F24B2F52C00F15587 /* WKWebView+JavaScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 08E7998E24B2F52C00F15587 /* WKWebView+JavaScript.m */; }; |
| 676 | 683 | 08FB8769215DD1C200DA5423 /* VoiceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB8767215DD1C200DA5423 /* VoiceViewController.m */; }; |
| 677 | 684 | 08FB876A215DD1C200DA5423 /* VoiceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB8767215DD1C200DA5423 /* VoiceViewController.m */; }; |
| ... | ... | @@ -1153,6 +1160,20 @@ |
| 1153 | 1160 | 08C090B421510E4B00E23D16 /* CNLiveTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveTableViewCell.m; sourceTree = "<group>"; }; |
| 1154 | 1161 | 08C090BD215116CB00E23D16 /* CNLiveIndicatorTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveIndicatorTableViewCell.h; sourceTree = "<group>"; }; |
| 1155 | 1162 | 08C090BE215116CB00E23D16 /* CNLiveIndicatorTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveIndicatorTableViewCell.m; sourceTree = "<group>"; }; |
| 1163 | + 08C721AA24CAC9B700970100 /* UIView+SDExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+SDExtension.h"; sourceTree = "<group>"; }; | |
| 1164 | + 08C721AB24CAC9B700970100 /* SDCycleScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCycleScrollView.h; sourceTree = "<group>"; }; | |
| 1165 | + 08C721AC24CAC9B700970100 /* SDCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCollectionViewCell.h; sourceTree = "<group>"; }; | |
| 1166 | + 08C721AD24CAC9B700970100 /* SDCycleScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCycleScrollView.m; sourceTree = "<group>"; }; | |
| 1167 | + 08C721AE24CAC9B700970100 /* UIView+SDExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+SDExtension.m"; sourceTree = "<group>"; }; | |
| 1168 | + 08C721AF24CAC9B700970100 /* SDCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCollectionViewCell.m; sourceTree = "<group>"; }; | |
| 1169 | + 08C721B124CAC9B700970100 /* TAAbstractDotView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TAAbstractDotView.h; sourceTree = "<group>"; }; | |
| 1170 | + 08C721B224CAC9B700970100 /* TADotView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TADotView.m; sourceTree = "<group>"; }; | |
| 1171 | + 08C721B324CAC9B700970100 /* TAPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TAPageControl.m; sourceTree = "<group>"; }; | |
| 1172 | + 08C721B424CAC9B700970100 /* TAAnimatedDotView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TAAnimatedDotView.m; sourceTree = "<group>"; }; | |
| 1173 | + 08C721B524CAC9B700970100 /* TAAbstractDotView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TAAbstractDotView.m; sourceTree = "<group>"; }; | |
| 1174 | + 08C721B624CAC9B700970100 /* TADotView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TADotView.h; sourceTree = "<group>"; }; | |
| 1175 | + 08C721B724CAC9B700970100 /* TAAnimatedDotView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TAAnimatedDotView.h; sourceTree = "<group>"; }; | |
| 1176 | + 08C721B824CAC9B700970100 /* TAPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TAPageControl.h; sourceTree = "<group>"; }; | |
| 1156 | 1177 | 08E7998D24B2F52C00F15587 /* WKWebView+JavaScript.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WKWebView+JavaScript.h"; sourceTree = "<group>"; }; |
| 1157 | 1178 | 08E7998E24B2F52C00F15587 /* WKWebView+JavaScript.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "WKWebView+JavaScript.m"; sourceTree = "<group>"; }; |
| 1158 | 1179 | 08FB8767215DD1C200DA5423 /* VoiceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VoiceViewController.m; sourceTree = "<group>"; }; |
| ... | ... | @@ -1980,6 +2001,7 @@ |
| 1980 | 2001 | 08C08FCF214FA01B00E23D16 /* Tools */ = { |
| 1981 | 2002 | isa = PBXGroup; |
| 1982 | 2003 | children = ( |
| 2004 | + 08C721A924CAC9B700970100 /* SDCycleScrollView */, | |
| 1983 | 2005 | 080AB4BE217AD457008BA78F /* ShareTool */, |
| 1984 | 2006 | 08585DD7215B70DA00FC2CA2 /* JSONKit */, |
| 1985 | 2007 | 08585D01215B4C7200FC2CA2 /* PGDatePicker */, |
| ... | ... | @@ -2387,6 +2409,35 @@ |
| 2387 | 2409 | path = XWHTTPTool; |
| 2388 | 2410 | sourceTree = "<group>"; |
| 2389 | 2411 | }; |
| 2412 | + 08C721A924CAC9B700970100 /* SDCycleScrollView */ = { | |
| 2413 | + isa = PBXGroup; | |
| 2414 | + children = ( | |
| 2415 | + 08C721AA24CAC9B700970100 /* UIView+SDExtension.h */, | |
| 2416 | + 08C721AB24CAC9B700970100 /* SDCycleScrollView.h */, | |
| 2417 | + 08C721AC24CAC9B700970100 /* SDCollectionViewCell.h */, | |
| 2418 | + 08C721AD24CAC9B700970100 /* SDCycleScrollView.m */, | |
| 2419 | + 08C721AE24CAC9B700970100 /* UIView+SDExtension.m */, | |
| 2420 | + 08C721AF24CAC9B700970100 /* SDCollectionViewCell.m */, | |
| 2421 | + 08C721B024CAC9B700970100 /* PageControl */, | |
| 2422 | + ); | |
| 2423 | + path = SDCycleScrollView; | |
| 2424 | + sourceTree = "<group>"; | |
| 2425 | + }; | |
| 2426 | + 08C721B024CAC9B700970100 /* PageControl */ = { | |
| 2427 | + isa = PBXGroup; | |
| 2428 | + children = ( | |
| 2429 | + 08C721B124CAC9B700970100 /* TAAbstractDotView.h */, | |
| 2430 | + 08C721B224CAC9B700970100 /* TADotView.m */, | |
| 2431 | + 08C721B324CAC9B700970100 /* TAPageControl.m */, | |
| 2432 | + 08C721B424CAC9B700970100 /* TAAnimatedDotView.m */, | |
| 2433 | + 08C721B524CAC9B700970100 /* TAAbstractDotView.m */, | |
| 2434 | + 08C721B624CAC9B700970100 /* TADotView.h */, | |
| 2435 | + 08C721B724CAC9B700970100 /* TAAnimatedDotView.h */, | |
| 2436 | + 08C721B824CAC9B700970100 /* TAPageControl.h */, | |
| 2437 | + ); | |
| 2438 | + path = PageControl; | |
| 2439 | + sourceTree = "<group>"; | |
| 2440 | + }; | |
| 2390 | 2441 | 08FB875A215DBBF000DA5423 /* Images */ = { |
| 2391 | 2442 | isa = PBXGroup; |
| 2392 | 2443 | children = ( |
| ... | ... | @@ -2983,6 +3034,7 @@ |
| 2983 | 3034 | 08C090872150C96C00E23D16 /* UIView+Extension.m in Sources */, |
| 2984 | 3035 | 08C090B521510E4B00E23D16 /* CNLiveTableViewCell.m in Sources */, |
| 2985 | 3036 | 085D86322159C72F0037D480 /* ZXVideoPlayerBrightnessView.m in Sources */, |
| 3037 | + 08C721BB24CAC9B700970100 /* SDCollectionViewCell.m in Sources */, | |
| 2986 | 3038 | 08C09007215082B700E23D16 /* XWTabBarModel.m in Sources */, |
| 2987 | 3039 | 08B5C5A121534DC700F5476E /* CNLiveRegisterEmailViewController.m in Sources */, |
| 2988 | 3040 | 08C090A62150F91A00E23D16 /* CNLiveNewPerspectiveViewController.m in Sources */, |
| ... | ... | @@ -3014,6 +3066,7 @@ |
| 3014 | 3066 | 08B5C5642153245200F5476E /* CNLiveLoginInputView.m in Sources */, |
| 3015 | 3067 | 08C090412150AA7300E23D16 /* CNMyTableViewCell.m in Sources */, |
| 3016 | 3068 | 08B5C57821533C0B00F5476E /* CNNewsoundListenViewController.m in Sources */, |
| 3069 | + 08C721BC24CAC9B700970100 /* TADotView.m in Sources */, | |
| 3017 | 3070 | 08B5C59C21534DB800F5476E /* CNLiveRegisterPhoneViewController.m in Sources */, |
| 3018 | 3071 | 08C090462150BC6500E23D16 /* CNMyTableViewHeaderView.m in Sources */, |
| 3019 | 3072 | 08585CE5215B302C00FC2CA2 /* CNLiveSearchViewController.m in Sources */, |
| ... | ... | @@ -3035,6 +3088,7 @@ |
| 3035 | 3088 | 08585D50215B4C7200FC2CA2 /* PGDatePicker+YearAndMonth.m in Sources */, |
| 3036 | 3089 | 08585DB8215B4DA300FC2CA2 /* ThreeImageTableViewCell.m in Sources */, |
| 3037 | 3090 | 08384857215CA75C00186618 /* OldVideoDetailViewController.m in Sources */, |
| 3091 | + 08C721BD24CAC9B700970100 /* TAPageControl.m in Sources */, | |
| 3038 | 3092 | 08585D41215B4C7200FC2CA2 /* PGDatePicker+MinuteAndSecond.m in Sources */, |
| 3039 | 3093 | 08C090912150CBDF00E23D16 /* CNLiveHeraldedNewsTableViewCell.m in Sources */, |
| 3040 | 3094 | 08585DBE215B4DA300FC2CA2 /* BigImageTableViewCell.m in Sources */, |
| ... | ... | @@ -3062,6 +3116,7 @@ |
| 3062 | 3116 | 08585DC3215B4E2B00FC2CA2 /* NoPictureTableViewCell.m in Sources */, |
| 3063 | 3117 | 08C090822150C79C00E23D16 /* ZXWSegmentControl.m in Sources */, |
| 3064 | 3118 | 08B5C5B221536BFF00F5476E /* AlertViewTool.m in Sources */, |
| 3119 | + 08C721B924CAC9B700970100 /* SDCycleScrollView.m in Sources */, | |
| 3065 | 3120 | 08585D80215B4C7200FC2CA2 /* PGDatePicker+TimeAndSecond.m in Sources */, |
| 3066 | 3121 | 084ACE3B2154C8310089E035 /* CNLiveNewsUpPicTableViewCell.m in Sources */, |
| 3067 | 3122 | 08C08FFA214FAFD400E23D16 /* UIViewController+XLSlideMenu.m in Sources */, |
| ... | ... | @@ -3070,6 +3125,7 @@ |
| 3070 | 3125 | 08C0908C2150CBA200E23D16 /* CNLiveHeraldedNewsViewController.m in Sources */, |
| 3071 | 3126 | 084ACDFD21547AE80089E035 /* CNLiveContactUsViewController.m in Sources */, |
| 3072 | 3127 | 08C090602150C3B200E23D16 /* CNLiveReporterAskedViewController.m in Sources */, |
| 3128 | + 08C721BF24CAC9B700970100 /* TAAbstractDotView.m in Sources */, | |
| 3073 | 3129 | 08C090A12150F8C000E23D16 /* CNLiveBeltRoadViewController.m in Sources */, |
| 3074 | 3130 | 084ACE362154C6D60089E035 /* CNLiveNewsLeftPicTableViewCell.m in Sources */, |
| 3075 | 3131 | 08585CF6215B3AA900FC2CA2 /* VideoTableViewCell.m in Sources */, |
| ... | ... | @@ -3078,8 +3134,10 @@ |
| 3078 | 3134 | 08384868215CAB1C00186618 /* YWWebScrollView.m in Sources */, |
| 3079 | 3135 | 084ACE18215481870089E035 /* NoDataView.m in Sources */, |
| 3080 | 3136 | 0838484D215CA73A00186618 /* OldArticleDetailViewController.m in Sources */, |
| 3137 | + 08C721BE24CAC9B700970100 /* TAAnimatedDotView.m in Sources */, | |
| 3081 | 3138 | 0838487D215CF6FC00186618 /* BaseViewController.m in Sources */, |
| 3082 | 3139 | C3004D35215A583400A83C3D /* CNLiveNewsDetailsView.m in Sources */, |
| 3140 | + 08C721BA24CAC9B700970100 /* UIView+SDExtension.m in Sources */, | |
| 3083 | 3141 | ); |
| 3084 | 3142 | runOnlyForDeploymentPostprocessing = 0; |
| 3085 | 3143 | }; | ... | ... |
CNLiveScioLive/Pages/Home/CNHomeENViewController.m
| ... | ... | @@ -15,12 +15,14 @@ |
| 15 | 15 | #import "CNLiveNewsUpPicTableViewCell.h" |
| 16 | 16 | #import "NoDataView.h" |
| 17 | 17 | |
| 18 | -@interface CNHomeENViewController ()<UITableViewDelegate,UITableViewDataSource> | |
| 18 | +@interface CNHomeENViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate> | |
| 19 | 19 | @property (nonatomic, strong) UITableView *tableView; |
| 20 | 20 | @property (nonatomic, strong) NSMutableArray *data; |
| 21 | 21 | @property (nonatomic, assign) NSInteger pageNo; |
| 22 | 22 | @property (nonatomic, assign) BOOL isRefreshing; |
| 23 | 23 | @property (nonatomic, strong) NoDataView *noDataView; |
| 24 | +@property (nonatomic, strong) SDCycleScrollView *cycleScrollView; | |
| 25 | +@property (nonatomic, strong) NSMutableArray *banner; | |
| 24 | 26 | |
| 25 | 27 | @end |
| 26 | 28 | |
| ... | ... | @@ -73,6 +75,32 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; |
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | } |
| 78 | + NSDictionary *ttName = dic[@"ttName"]; | |
| 79 | + NSArray *programs = ttName[@"programs"]; | |
| 80 | + | |
| 81 | + if ([programs isKindOfClass:[NSArray class]]) { | |
| 82 | + [self.banner removeAllObjects]; | |
| 83 | + for (NSDictionary *dics in programs) { | |
| 84 | + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{ | |
| 85 | + return @{ @"ID" : @"id" ,@"Description" : @"description" }; | |
| 86 | + }]; | |
| 87 | + | |
| 88 | + NSLog(@"%@",dics); | |
| 89 | + [self.banner addObject:[CNHomeModel mj_objectWithKeyValues:dics]]; | |
| 90 | + } | |
| 91 | + | |
| 92 | + NSMutableArray *titles = [NSMutableArray array]; | |
| 93 | + NSMutableArray *imagesURLStrings = [NSMutableArray array]; | |
| 94 | + for(int i = 0; i < self.banner.count; i++){ | |
| 95 | + CNHomeModel *model = self.banner[i]; | |
| 96 | + [titles addObject:model.title]; | |
| 97 | + [imagesURLStrings addObject:model.img]; | |
| 98 | + | |
| 99 | + } | |
| 100 | + self.cycleScrollView.titlesGroup = titles; | |
| 101 | + self.cycleScrollView.imageURLStringsGroup = imagesURLStrings; | |
| 102 | + | |
| 103 | + } | |
| 76 | 104 | |
| 77 | 105 | } else { |
| 78 | 106 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; |
| ... | ... | @@ -123,6 +151,8 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; |
| 123 | 151 | _isRefreshing = NO; |
| 124 | 152 | |
| 125 | 153 | [self.view addSubview:self.tableView]; |
| 154 | + self.tableView.tableHeaderView = self.cycleScrollView; | |
| 155 | + | |
| 126 | 156 | [self loadData]; |
| 127 | 157 | |
| 128 | 158 | // Do any additional setup after loading the view. |
| ... | ... | @@ -265,6 +295,12 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; |
| 265 | 295 | CNHomeModel *model = self.data[indexPath.row]; |
| 266 | 296 | [self pushViewControllerWithModel:model]; |
| 267 | 297 | } |
| 298 | +#pragma mark - SDCycleScrollViewDelegate | |
| 299 | + | |
| 300 | +- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { | |
| 301 | + CNHomeModel *model = self.banner[index]; | |
| 302 | + [self pushViewControllerWithModel:model]; | |
| 303 | +} | |
| 268 | 304 | /* |
| 269 | 305 | #pragma mark - Navigation |
| 270 | 306 | |
| ... | ... | @@ -375,4 +411,28 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell"; |
| 375 | 411 | return _noDataView; |
| 376 | 412 | } |
| 377 | 413 | |
| 414 | +- (SDCycleScrollView *)cycleScrollView{ | |
| 415 | + | |
| 416 | + if(!_cycleScrollView){ | |
| 417 | + | |
| 418 | + _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenWidth*9/16.0) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; | |
| 419 | + _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter; | |
| 420 | + _cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色 | |
| 421 | + _cycleScrollView.titleLabelTextFont = [UIFont systemFontOfSize:15*MainHScale]; | |
| 422 | + _cycleScrollView.titleLabelHeight = 50*MainHScale; | |
| 423 | + _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; | |
| 424 | + _cycleScrollView.titleLabelTextColor = [UIColor whiteColor]; | |
| 425 | + _cycleScrollView.titleLabelBackgroundColor = [UIColor clearColor]; | |
| 426 | + _cycleScrollView.titleLabelTextAlignment = NSTextAlignmentLeft; | |
| 427 | + _cycleScrollView.delegate = self; | |
| 428 | + } | |
| 429 | + return _cycleScrollView; | |
| 430 | + | |
| 431 | +} | |
| 432 | +- (NSMutableArray *)banner{ | |
| 433 | + if(!_banner){ | |
| 434 | + _banner = [[NSMutableArray alloc] init]; | |
| 435 | + } | |
| 436 | + return _banner; | |
| 437 | +} | |
| 378 | 438 | @end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAAbstractDotView.h
0 → 100755
| 1 | +// | |
| 2 | +// TAAbstractDotView.h | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-22. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | + | |
| 12 | +@interface TAAbstractDotView : UIView | |
| 13 | + | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * A method call let view know which state appearance it should take. Active meaning it's current page. Inactive not the current page. | |
| 17 | + * | |
| 18 | + * @param active BOOL to tell if view is active or not | |
| 19 | + */ | |
| 20 | +- (void)changeActivityState:(BOOL)active; | |
| 21 | + | |
| 22 | + | |
| 23 | +@end | |
| 24 | + | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAAbstractDotView.m
0 → 100755
| 1 | +// | |
| 2 | +// TAAbstractDotView.m | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-22. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "TAAbstractDotView.h" | |
| 10 | + | |
| 11 | + | |
| 12 | +@implementation TAAbstractDotView | |
| 13 | + | |
| 14 | + | |
| 15 | +- (id)init | |
| 16 | +{ | |
| 17 | + @throw [NSException exceptionWithName:NSInternalInconsistencyException | |
| 18 | + reason:[NSString stringWithFormat:@"You must override %@ in %@", NSStringFromSelector(_cmd), self.class] | |
| 19 | + userInfo:nil]; | |
| 20 | +} | |
| 21 | + | |
| 22 | + | |
| 23 | +- (void)changeActivityState:(BOOL)active | |
| 24 | +{ | |
| 25 | + @throw [NSException exceptionWithName:NSInternalInconsistencyException | |
| 26 | + reason:[NSString stringWithFormat:@"You must override %@ in %@", NSStringFromSelector(_cmd), self.class] | |
| 27 | + userInfo:nil]; | |
| 28 | +} | |
| 29 | + | |
| 30 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAAnimatedDotView.h
0 → 100755
| 1 | +// | |
| 2 | +// TAAnimatedDotView.h | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-22. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "TAAbstractDotView.h" | |
| 10 | + | |
| 11 | +@interface TAAnimatedDotView : TAAbstractDotView | |
| 12 | + | |
| 13 | +@property (nonatomic, strong) UIColor *dotColor; | |
| 14 | + | |
| 15 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAAnimatedDotView.m
0 → 100755
| 1 | +// | |
| 2 | +// TAAnimatedDotView.m | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-22. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "TAAnimatedDotView.h" | |
| 10 | + | |
| 11 | +static CGFloat const kAnimateDuration = 1; | |
| 12 | + | |
| 13 | +@implementation TAAnimatedDotView | |
| 14 | + | |
| 15 | +- (instancetype)init | |
| 16 | +{ | |
| 17 | + self = [super init]; | |
| 18 | + if (self) { | |
| 19 | + [self initialization]; | |
| 20 | + } | |
| 21 | + | |
| 22 | + return self; | |
| 23 | +} | |
| 24 | + | |
| 25 | + | |
| 26 | +- (id)initWithFrame:(CGRect)frame | |
| 27 | +{ | |
| 28 | + self = [super initWithFrame:frame]; | |
| 29 | + if (self) { | |
| 30 | + [self initialization]; | |
| 31 | + } | |
| 32 | + return self; | |
| 33 | +} | |
| 34 | + | |
| 35 | + | |
| 36 | +- (id)initWithCoder:(NSCoder *)aDecoder | |
| 37 | +{ | |
| 38 | + self = [super initWithCoder:aDecoder]; | |
| 39 | + if (self) { | |
| 40 | + [self initialization]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + return self; | |
| 44 | +} | |
| 45 | + | |
| 46 | +- (void)setDotColor:(UIColor *)dotColor | |
| 47 | +{ | |
| 48 | + _dotColor = dotColor; | |
| 49 | + self.layer.borderColor = dotColor.CGColor; | |
| 50 | +} | |
| 51 | + | |
| 52 | +- (void)initialization | |
| 53 | +{ | |
| 54 | + _dotColor = [UIColor whiteColor]; | |
| 55 | + self.backgroundColor = [UIColor clearColor]; | |
| 56 | + self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2; | |
| 57 | + self.layer.borderColor = [UIColor whiteColor].CGColor; | |
| 58 | + self.layer.borderWidth = 2; | |
| 59 | +} | |
| 60 | + | |
| 61 | + | |
| 62 | +- (void)changeActivityState:(BOOL)active | |
| 63 | +{ | |
| 64 | + if (active) { | |
| 65 | + [self animateToActiveState]; | |
| 66 | + } else { | |
| 67 | + [self animateToDeactiveState]; | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | + | |
| 72 | +- (void)animateToActiveState | |
| 73 | +{ | |
| 74 | + [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:-20 options:UIViewAnimationOptionCurveLinear animations:^{ | |
| 75 | + self.backgroundColor = _dotColor; | |
| 76 | + self.transform = CGAffineTransformMakeScale(1.4, 1.4); | |
| 77 | + } completion:nil]; | |
| 78 | +} | |
| 79 | + | |
| 80 | +- (void)animateToDeactiveState | |
| 81 | +{ | |
| 82 | + [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ | |
| 83 | + self.backgroundColor = [UIColor clearColor]; | |
| 84 | + self.transform = CGAffineTransformIdentity; | |
| 85 | + } completion:nil]; | |
| 86 | +} | |
| 87 | + | |
| 88 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TADotView.h
0 → 100755
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TADotView.m
0 → 100755
| 1 | +// | |
| 2 | +// TADotView.m | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-22. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "TADotView.h" | |
| 10 | + | |
| 11 | +@implementation TADotView | |
| 12 | + | |
| 13 | + | |
| 14 | +- (instancetype)init | |
| 15 | +{ | |
| 16 | + self = [super init]; | |
| 17 | + if (self) { | |
| 18 | + [self initialization]; | |
| 19 | + } | |
| 20 | + | |
| 21 | + return self; | |
| 22 | +} | |
| 23 | + | |
| 24 | + | |
| 25 | +- (id)initWithFrame:(CGRect)frame | |
| 26 | +{ | |
| 27 | + self = [super initWithFrame:frame]; | |
| 28 | + if (self) { | |
| 29 | + [self initialization]; | |
| 30 | + } | |
| 31 | + return self; | |
| 32 | +} | |
| 33 | + | |
| 34 | + | |
| 35 | +- (id)initWithCoder:(NSCoder *)aDecoder | |
| 36 | +{ | |
| 37 | + self = [super initWithCoder:aDecoder]; | |
| 38 | + if (self) { | |
| 39 | + [self initialization]; | |
| 40 | + } | |
| 41 | + | |
| 42 | + return self; | |
| 43 | +} | |
| 44 | + | |
| 45 | +- (void)initialization | |
| 46 | +{ | |
| 47 | + self.backgroundColor = [UIColor clearColor]; | |
| 48 | + self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2; | |
| 49 | + self.layer.borderColor = [UIColor whiteColor].CGColor; | |
| 50 | + self.layer.borderWidth = 2; | |
| 51 | +} | |
| 52 | + | |
| 53 | + | |
| 54 | +- (void)changeActivityState:(BOOL)active | |
| 55 | +{ | |
| 56 | + if (active) { | |
| 57 | + self.backgroundColor = [UIColor whiteColor]; | |
| 58 | + } else { | |
| 59 | + self.backgroundColor = [UIColor clearColor]; | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAPageControl.h
0 → 100755
| 1 | +// | |
| 2 | +// TAPageControl.h | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-21. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +@protocol TAPageControlDelegate; | |
| 12 | + | |
| 13 | + | |
| 14 | +@interface TAPageControl : UIControl | |
| 15 | + | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * Dot view customization properties | |
| 19 | + */ | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * The Class of your custom UIView, make sure to respect the TAAbstractDotView class. | |
| 23 | + */ | |
| 24 | +@property (nonatomic) Class dotViewClass; | |
| 25 | + | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * UIImage to represent a dot. | |
| 29 | + */ | |
| 30 | +@property (nonatomic) UIImage *dotImage; | |
| 31 | + | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * UIImage to represent current page dot. | |
| 35 | + */ | |
| 36 | +@property (nonatomic) UIImage *currentDotImage; | |
| 37 | + | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * Dot size for dot views. Default is 8 by 8. | |
| 41 | + */ | |
| 42 | +@property (nonatomic) CGSize dotSize; | |
| 43 | + | |
| 44 | + | |
| 45 | +@property (nonatomic, strong) UIColor *dotColor; | |
| 46 | + | |
| 47 | +/** | |
| 48 | + * Spacing between two dot views. Default is 8. | |
| 49 | + */ | |
| 50 | +@property (nonatomic) NSInteger spacingBetweenDots; | |
| 51 | + | |
| 52 | + | |
| 53 | +/** | |
| 54 | + * Page control setup properties | |
| 55 | + */ | |
| 56 | + | |
| 57 | + | |
| 58 | +/** | |
| 59 | + * Delegate for TAPageControl | |
| 60 | + */ | |
| 61 | +@property(nonatomic,assign) id<TAPageControlDelegate> delegate; | |
| 62 | + | |
| 63 | + | |
| 64 | +/** | |
| 65 | + * Number of pages for control. Default is 0. | |
| 66 | + */ | |
| 67 | +@property (nonatomic) NSInteger numberOfPages; | |
| 68 | + | |
| 69 | + | |
| 70 | +/** | |
| 71 | + * Current page on which control is active. Default is 0. | |
| 72 | + */ | |
| 73 | +@property (nonatomic) NSInteger currentPage; | |
| 74 | + | |
| 75 | + | |
| 76 | +/** | |
| 77 | + * Hide the control if there is only one page. Default is NO. | |
| 78 | + */ | |
| 79 | +@property (nonatomic) BOOL hidesForSinglePage; | |
| 80 | + | |
| 81 | + | |
| 82 | +/** | |
| 83 | + * Let the control know if should grow bigger by keeping center, or just get longer (right side expanding). By default YES. | |
| 84 | + */ | |
| 85 | +@property (nonatomic) BOOL shouldResizeFromCenter; | |
| 86 | + | |
| 87 | + | |
| 88 | +/** | |
| 89 | + * Return the minimum size required to display control properly for the given page count. | |
| 90 | + * | |
| 91 | + * @param pageCount Number of dots that will require display | |
| 92 | + * | |
| 93 | + * @return The CGSize being the minimum size required. | |
| 94 | + */ | |
| 95 | +- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount; | |
| 96 | + | |
| 97 | + | |
| 98 | +@end | |
| 99 | + | |
| 100 | + | |
| 101 | +@protocol TAPageControlDelegate <NSObject> | |
| 102 | + | |
| 103 | +@optional | |
| 104 | +- (void)TAPageControl:(TAPageControl *)pageControl didSelectPageAtIndex:(NSInteger)index; | |
| 105 | + | |
| 106 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/PageControl/TAPageControl.m
0 → 100755
| 1 | +// | |
| 2 | +// TAPageControl.m | |
| 3 | +// TAPageControl | |
| 4 | +// | |
| 5 | +// Created by Tanguy Aladenise on 2015-01-21. | |
| 6 | +// Copyright (c) 2015 Tanguy Aladenise. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "TAPageControl.h" | |
| 10 | +#import "TAAbstractDotView.h" | |
| 11 | +#import "TAAnimatedDotView.h" | |
| 12 | +#import "TADotView.h" | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Default number of pages for initialization | |
| 16 | + */ | |
| 17 | +static NSInteger const kDefaultNumberOfPages = 0; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Default current page for initialization | |
| 21 | + */ | |
| 22 | +static NSInteger const kDefaultCurrentPage = 0; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * Default setting for hide for single page feature. For initialization | |
| 26 | + */ | |
| 27 | +static BOOL const kDefaultHideForSinglePage = NO; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Default setting for shouldResizeFromCenter. For initialiation | |
| 31 | + */ | |
| 32 | +static BOOL const kDefaultShouldResizeFromCenter = YES; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Default spacing between dots | |
| 36 | + */ | |
| 37 | +static NSInteger const kDefaultSpacingBetweenDots = 8; | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * Default dot size | |
| 41 | + */ | |
| 42 | +static CGSize const kDefaultDotSize = {8, 8}; | |
| 43 | + | |
| 44 | + | |
| 45 | +@interface TAPageControl() | |
| 46 | + | |
| 47 | + | |
| 48 | +/** | |
| 49 | + * Array of dot views for reusability and touch events. | |
| 50 | + */ | |
| 51 | +@property (strong, nonatomic) NSMutableArray *dots; | |
| 52 | + | |
| 53 | + | |
| 54 | +@end | |
| 55 | + | |
| 56 | +@implementation TAPageControl | |
| 57 | + | |
| 58 | + | |
| 59 | +#pragma mark - Lifecycle | |
| 60 | + | |
| 61 | + | |
| 62 | +- (id)init | |
| 63 | +{ | |
| 64 | + self = [super init]; | |
| 65 | + if (self) { | |
| 66 | + [self initialization]; | |
| 67 | + } | |
| 68 | + | |
| 69 | + return self; | |
| 70 | +} | |
| 71 | + | |
| 72 | + | |
| 73 | +- (id)initWithFrame:(CGRect)frame | |
| 74 | +{ | |
| 75 | + self = [super initWithFrame:frame]; | |
| 76 | + if (self) { | |
| 77 | + [self initialization]; | |
| 78 | + } | |
| 79 | + return self; | |
| 80 | +} | |
| 81 | + | |
| 82 | + | |
| 83 | +- (id)initWithCoder:(NSCoder *)aDecoder | |
| 84 | +{ | |
| 85 | + self = [super initWithCoder:aDecoder]; | |
| 86 | + if (self) { | |
| 87 | + [self initialization]; | |
| 88 | + } | |
| 89 | + | |
| 90 | + return self; | |
| 91 | +} | |
| 92 | + | |
| 93 | + | |
| 94 | +/** | |
| 95 | + * Default setup when initiating control | |
| 96 | + */ | |
| 97 | +- (void)initialization | |
| 98 | +{ | |
| 99 | + self.dotViewClass = [TAAnimatedDotView class]; | |
| 100 | + self.spacingBetweenDots = kDefaultSpacingBetweenDots; | |
| 101 | + self.numberOfPages = kDefaultNumberOfPages; | |
| 102 | + self.currentPage = kDefaultCurrentPage; | |
| 103 | + self.hidesForSinglePage = kDefaultHideForSinglePage; | |
| 104 | + self.shouldResizeFromCenter = kDefaultShouldResizeFromCenter; | |
| 105 | +} | |
| 106 | + | |
| 107 | + | |
| 108 | +#pragma mark - Touch event | |
| 109 | + | |
| 110 | +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | |
| 111 | +{ | |
| 112 | + UITouch *touch = [touches anyObject]; | |
| 113 | + if (touch.view != self) { | |
| 114 | + NSInteger index = [self.dots indexOfObject:touch.view]; | |
| 115 | + if ([self.delegate respondsToSelector:@selector(TAPageControl:didSelectPageAtIndex:)]) { | |
| 116 | + [self.delegate TAPageControl:self didSelectPageAtIndex:index]; | |
| 117 | + } | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +#pragma mark - Layout | |
| 122 | + | |
| 123 | + | |
| 124 | +/** | |
| 125 | + * Resizes and moves the receiver view so it just encloses its subviews. | |
| 126 | + */ | |
| 127 | +- (void)sizeToFit | |
| 128 | +{ | |
| 129 | + [self updateFrame:YES]; | |
| 130 | +} | |
| 131 | + | |
| 132 | + | |
| 133 | +- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount | |
| 134 | +{ | |
| 135 | + return CGSizeMake((self.dotSize.width + self.spacingBetweenDots) * pageCount - self.spacingBetweenDots , self.dotSize.height); | |
| 136 | +} | |
| 137 | + | |
| 138 | + | |
| 139 | +/** | |
| 140 | + * Will update dots display and frame. Reuse existing views or instantiate one if required. Update their position in case frame changed. | |
| 141 | + */ | |
| 142 | +- (void)updateDots | |
| 143 | +{ | |
| 144 | + if (self.numberOfPages == 0) { | |
| 145 | + return; | |
| 146 | + } | |
| 147 | + | |
| 148 | + for (NSInteger i = 0; i < self.numberOfPages; i++) { | |
| 149 | + | |
| 150 | + UIView *dot; | |
| 151 | + if (i < self.dots.count) { | |
| 152 | + dot = [self.dots objectAtIndex:i]; | |
| 153 | + } else { | |
| 154 | + dot = [self generateDotView]; | |
| 155 | + } | |
| 156 | + | |
| 157 | + [self updateDotFrame:dot atIndex:i]; | |
| 158 | + } | |
| 159 | + | |
| 160 | + [self changeActivity:YES atIndex:self.currentPage]; | |
| 161 | + | |
| 162 | + [self hideForSinglePage]; | |
| 163 | +} | |
| 164 | + | |
| 165 | + | |
| 166 | +/** | |
| 167 | + * Update frame control to fit current number of pages. It will apply required size if authorize and required. | |
| 168 | + * | |
| 169 | + * @param overrideExistingFrame BOOL to allow frame to be overriden. Meaning the required size will be apply no mattter what. | |
| 170 | + */ | |
| 171 | +- (void)updateFrame:(BOOL)overrideExistingFrame | |
| 172 | +{ | |
| 173 | + CGPoint center = self.center; | |
| 174 | + CGSize requiredSize = [self sizeForNumberOfPages:self.numberOfPages]; | |
| 175 | + | |
| 176 | + // We apply requiredSize only if authorize to and necessary | |
| 177 | + if (overrideExistingFrame || ((CGRectGetWidth(self.frame) < requiredSize.width || CGRectGetHeight(self.frame) < requiredSize.height) && !overrideExistingFrame)) { | |
| 178 | + self.frame = CGRectMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame), requiredSize.width, requiredSize.height); | |
| 179 | + if (self.shouldResizeFromCenter) { | |
| 180 | + self.center = center; | |
| 181 | + } | |
| 182 | + } | |
| 183 | + | |
| 184 | + [self resetDotViews]; | |
| 185 | +} | |
| 186 | + | |
| 187 | + | |
| 188 | +/** | |
| 189 | + * Update the frame of a specific dot at a specific index | |
| 190 | + * | |
| 191 | + * @param dot Dot view | |
| 192 | + * @param index Page index of dot | |
| 193 | + */ | |
| 194 | +- (void)updateDotFrame:(UIView *)dot atIndex:(NSInteger)index | |
| 195 | +{ | |
| 196 | + // Dots are always centered within view | |
| 197 | + CGFloat x = (self.dotSize.width + self.spacingBetweenDots) * index + ( (CGRectGetWidth(self.frame) - [self sizeForNumberOfPages:self.numberOfPages].width) / 2); | |
| 198 | + CGFloat y = (CGRectGetHeight(self.frame) - self.dotSize.height) / 2; | |
| 199 | + | |
| 200 | + dot.frame = CGRectMake(x, y, self.dotSize.width, self.dotSize.height); | |
| 201 | +} | |
| 202 | + | |
| 203 | + | |
| 204 | +#pragma mark - Utils | |
| 205 | + | |
| 206 | + | |
| 207 | +/** | |
| 208 | + * Generate a dot view and add it to the collection | |
| 209 | + * | |
| 210 | + * @return The UIView object representing a dot | |
| 211 | + */ | |
| 212 | +- (UIView *)generateDotView | |
| 213 | +{ | |
| 214 | + UIView *dotView; | |
| 215 | + | |
| 216 | + if (self.dotViewClass) { | |
| 217 | + dotView = [[self.dotViewClass alloc] initWithFrame:CGRectMake(0, 0, self.dotSize.width, self.dotSize.height)]; | |
| 218 | + if ([dotView isKindOfClass:[TAAnimatedDotView class]] && self.dotColor) { | |
| 219 | + ((TAAnimatedDotView *)dotView).dotColor = self.dotColor; | |
| 220 | + } | |
| 221 | + } else { | |
| 222 | + dotView = [[UIImageView alloc] initWithImage:self.dotImage]; | |
| 223 | + dotView.frame = CGRectMake(0, 0, self.dotSize.width, self.dotSize.height); | |
| 224 | + } | |
| 225 | + | |
| 226 | + if (dotView) { | |
| 227 | + [self addSubview:dotView]; | |
| 228 | + [self.dots addObject:dotView]; | |
| 229 | + } | |
| 230 | + | |
| 231 | + dotView.userInteractionEnabled = YES; | |
| 232 | + return dotView; | |
| 233 | +} | |
| 234 | + | |
| 235 | + | |
| 236 | +/** | |
| 237 | + * Change activity state of a dot view. Current/not currrent. | |
| 238 | + * | |
| 239 | + * @param active Active state to apply | |
| 240 | + * @param index Index of dot for state update | |
| 241 | + */ | |
| 242 | +- (void)changeActivity:(BOOL)active atIndex:(NSInteger)index | |
| 243 | +{ | |
| 244 | + if (self.dotViewClass) { | |
| 245 | + TAAbstractDotView *abstractDotView = (TAAbstractDotView *)[self.dots objectAtIndex:index]; | |
| 246 | + if ([abstractDotView respondsToSelector:@selector(changeActivityState:)]) { | |
| 247 | + [abstractDotView changeActivityState:active]; | |
| 248 | + } else { | |
| 249 | + NSLog(@"Custom view : %@ must implement an 'changeActivityState' method or you can subclass %@ to help you.", self.dotViewClass, [TAAbstractDotView class]); | |
| 250 | + } | |
| 251 | + } else if (self.dotImage && self.currentDotImage) { | |
| 252 | + UIImageView *dotView = (UIImageView *)[self.dots objectAtIndex:index]; | |
| 253 | + dotView.image = (active) ? self.currentDotImage : self.dotImage; | |
| 254 | + } | |
| 255 | +} | |
| 256 | + | |
| 257 | + | |
| 258 | +- (void)resetDotViews | |
| 259 | +{ | |
| 260 | + for (UIView *dotView in self.dots) { | |
| 261 | + [dotView removeFromSuperview]; | |
| 262 | + } | |
| 263 | + | |
| 264 | + [self.dots removeAllObjects]; | |
| 265 | + [self updateDots]; | |
| 266 | +} | |
| 267 | + | |
| 268 | + | |
| 269 | +- (void)hideForSinglePage | |
| 270 | +{ | |
| 271 | + if (self.dots.count == 1 && self.hidesForSinglePage) { | |
| 272 | + self.hidden = YES; | |
| 273 | + } else { | |
| 274 | + self.hidden = NO; | |
| 275 | + } | |
| 276 | +} | |
| 277 | + | |
| 278 | +#pragma mark - Setters | |
| 279 | + | |
| 280 | + | |
| 281 | +- (void)setNumberOfPages:(NSInteger)numberOfPages | |
| 282 | +{ | |
| 283 | + _numberOfPages = numberOfPages; | |
| 284 | + | |
| 285 | + // Update dot position to fit new number of pages | |
| 286 | + [self resetDotViews]; | |
| 287 | +} | |
| 288 | + | |
| 289 | + | |
| 290 | +- (void)setSpacingBetweenDots:(NSInteger)spacingBetweenDots | |
| 291 | +{ | |
| 292 | + _spacingBetweenDots = spacingBetweenDots; | |
| 293 | + | |
| 294 | + [self resetDotViews]; | |
| 295 | +} | |
| 296 | + | |
| 297 | + | |
| 298 | +- (void)setCurrentPage:(NSInteger)currentPage | |
| 299 | +{ | |
| 300 | + // If no pages, no current page to treat. | |
| 301 | + if (self.numberOfPages == 0 || currentPage == _currentPage) { | |
| 302 | + _currentPage = currentPage; | |
| 303 | + return; | |
| 304 | + } | |
| 305 | + | |
| 306 | + // Pre set | |
| 307 | + [self changeActivity:NO atIndex:_currentPage]; | |
| 308 | + _currentPage = currentPage; | |
| 309 | + // Post set | |
| 310 | + [self changeActivity:YES atIndex:_currentPage]; | |
| 311 | +} | |
| 312 | + | |
| 313 | + | |
| 314 | +- (void)setDotImage:(UIImage *)dotImage | |
| 315 | +{ | |
| 316 | + _dotImage = dotImage; | |
| 317 | + [self resetDotViews]; | |
| 318 | + self.dotViewClass = nil; | |
| 319 | +} | |
| 320 | + | |
| 321 | + | |
| 322 | +- (void)setCurrentDotImage:(UIImage *)currentDotimage | |
| 323 | +{ | |
| 324 | + _currentDotImage = currentDotimage; | |
| 325 | + [self resetDotViews]; | |
| 326 | + self.dotViewClass = nil; | |
| 327 | +} | |
| 328 | + | |
| 329 | + | |
| 330 | +- (void)setDotViewClass:(Class)dotViewClass | |
| 331 | +{ | |
| 332 | + _dotViewClass = dotViewClass; | |
| 333 | + self.dotSize = CGSizeZero; | |
| 334 | + [self resetDotViews]; | |
| 335 | +} | |
| 336 | + | |
| 337 | + | |
| 338 | +#pragma mark - Getters | |
| 339 | + | |
| 340 | + | |
| 341 | +- (NSMutableArray *)dots | |
| 342 | +{ | |
| 343 | + if (!_dots) { | |
| 344 | + _dots = [[NSMutableArray alloc] init]; | |
| 345 | + } | |
| 346 | + | |
| 347 | + return _dots; | |
| 348 | +} | |
| 349 | + | |
| 350 | + | |
| 351 | +- (CGSize)dotSize | |
| 352 | +{ | |
| 353 | + // Dot size logic depending on the source of the dot view | |
| 354 | + if (self.dotImage && CGSizeEqualToSize(_dotSize, CGSizeZero)) { | |
| 355 | + _dotSize = self.dotImage.size; | |
| 356 | + } else if (self.dotViewClass && CGSizeEqualToSize(_dotSize, CGSizeZero)) { | |
| 357 | + _dotSize = kDefaultDotSize; | |
| 358 | + return _dotSize; | |
| 359 | + } | |
| 360 | + | |
| 361 | + return _dotSize; | |
| 362 | +} | |
| 363 | + | |
| 364 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/SDCollectionViewCell.h
0 → 100644
| 1 | +// | |
| 2 | +// SDCollectionViewCell.h | |
| 3 | +// SDCycleScrollView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-3-22. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/* | |
| 10 | + | |
| 11 | + ********************************************************************************* | |
| 12 | + * | |
| 13 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 14 | + * | |
| 15 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 16 | + * 帮您解决问题。 | |
| 17 | + * 新浪微博:GSD_iOS | |
| 18 | + * Email : gsdios@126.com | |
| 19 | + * GitHub: https://github.com/gsdios | |
| 20 | + * | |
| 21 | + * 另(我的自动布局库SDAutoLayout): | |
| 22 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 23 | + * 做最简单易用的AutoLayout库。 | |
| 24 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 25 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 26 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 27 | + ********************************************************************************* | |
| 28 | + | |
| 29 | + */ | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | +#import <UIKit/UIKit.h> | |
| 34 | + | |
| 35 | +@interface SDCollectionViewCell : UICollectionViewCell | |
| 36 | + | |
| 37 | +@property (weak, nonatomic) UIImageView *imageView; | |
| 38 | +@property (copy, nonatomic) NSString *title; | |
| 39 | + | |
| 40 | +@property (nonatomic, strong) UIColor *titleLabelTextColor; | |
| 41 | +@property (nonatomic, strong) UIFont *titleLabelTextFont; | |
| 42 | +@property (nonatomic, strong) UIColor *titleLabelBackgroundColor; | |
| 43 | +@property (nonatomic, assign) CGFloat titleLabelHeight; | |
| 44 | +@property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment; | |
| 45 | + | |
| 46 | +@property (nonatomic, assign) BOOL hasConfigured; | |
| 47 | + | |
| 48 | +/** 只展示文字轮播 */ | |
| 49 | +@property (nonatomic, assign) BOOL onlyDisplayText; | |
| 50 | + | |
| 51 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/SDCollectionViewCell.m
0 → 100644
| 1 | +// | |
| 2 | +// SDCollectionViewCell.m | |
| 3 | +// SDCycleScrollView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-3-22. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | + | |
| 10 | +/* | |
| 11 | + | |
| 12 | + ********************************************************************************* | |
| 13 | + * | |
| 14 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 15 | + * | |
| 16 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 17 | + * 帮您解决问题。 | |
| 18 | + * 新浪微博:GSD_iOS | |
| 19 | + * Email : gsdios@126.com | |
| 20 | + * GitHub: https://github.com/gsdios | |
| 21 | + * | |
| 22 | + * 另(我的自动布局库SDAutoLayout): | |
| 23 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 24 | + * 做最简单易用的AutoLayout库。 | |
| 25 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 26 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 27 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 28 | + ********************************************************************************* | |
| 29 | + | |
| 30 | + */ | |
| 31 | + | |
| 32 | + | |
| 33 | +#import "SDCollectionViewCell.h" | |
| 34 | +#import "UIView+SDExtension.h" | |
| 35 | + | |
| 36 | +@implementation SDCollectionViewCell | |
| 37 | +{ | |
| 38 | + __weak UILabel *_titleLabel; | |
| 39 | + UIView *_bgView; | |
| 40 | + | |
| 41 | +} | |
| 42 | + | |
| 43 | + | |
| 44 | +- (instancetype)initWithFrame:(CGRect)frame | |
| 45 | +{ | |
| 46 | + if (self = [super initWithFrame:frame]) { | |
| 47 | + [self setupImageView]; | |
| 48 | + [self setupTitleLabel]; | |
| 49 | + } | |
| 50 | + | |
| 51 | + return self; | |
| 52 | +} | |
| 53 | + | |
| 54 | +- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor | |
| 55 | +{ | |
| 56 | + _titleLabelBackgroundColor = titleLabelBackgroundColor; | |
| 57 | + _titleLabel.backgroundColor = titleLabelBackgroundColor; | |
| 58 | +} | |
| 59 | + | |
| 60 | +- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor | |
| 61 | +{ | |
| 62 | + _titleLabelTextColor = titleLabelTextColor; | |
| 63 | + _titleLabel.textColor = titleLabelTextColor; | |
| 64 | +} | |
| 65 | + | |
| 66 | +- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont | |
| 67 | +{ | |
| 68 | + _titleLabelTextFont = titleLabelTextFont; | |
| 69 | + _titleLabel.font = titleLabelTextFont; | |
| 70 | +} | |
| 71 | + | |
| 72 | +- (void)setupImageView | |
| 73 | +{ | |
| 74 | + UIImageView *imageView = [[UIImageView alloc] init]; | |
| 75 | + _imageView = imageView; | |
| 76 | + [self.contentView addSubview:imageView]; | |
| 77 | +} | |
| 78 | + | |
| 79 | +- (void)setupTitleLabel | |
| 80 | +{ | |
| 81 | + UILabel *titleLabel = [[UILabel alloc] init]; | |
| 82 | + titleLabel.numberOfLines = 2; | |
| 83 | + _titleLabel = titleLabel; | |
| 84 | + _titleLabel.hidden = YES; | |
| 85 | + [self.contentView addSubview:titleLabel]; | |
| 86 | +} | |
| 87 | + | |
| 88 | +- (void)setTitle:(NSString *)title | |
| 89 | +{ | |
| 90 | + _title = [title copy]; | |
| 91 | + _titleLabel.text = [NSString stringWithFormat:@" %@", title]; | |
| 92 | + if (_titleLabel.hidden) { | |
| 93 | + _titleLabel.hidden = NO; | |
| 94 | + } | |
| 95 | +} | |
| 96 | + | |
| 97 | +-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment | |
| 98 | +{ | |
| 99 | + _titleLabelTextAlignment = titleLabelTextAlignment; | |
| 100 | + _titleLabel.textAlignment = titleLabelTextAlignment; | |
| 101 | +} | |
| 102 | + | |
| 103 | +- (void)layoutSubviews | |
| 104 | +{ | |
| 105 | + [super layoutSubviews]; | |
| 106 | + | |
| 107 | + if (self.onlyDisplayText) { | |
| 108 | + _titleLabel.frame = self.bounds; | |
| 109 | + } else { | |
| 110 | + _imageView.frame = self.bounds; | |
| 111 | + CGFloat titleLabelW = self.sd_width; | |
| 112 | + CGFloat titleLabelH = _titleLabelHeight; | |
| 113 | + CGFloat titleLabelX = 10; | |
| 114 | + CGFloat titleLabelY = self.sd_height - titleLabelH-20; | |
| 115 | + _titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW-2*titleLabelX, titleLabelH); | |
| 116 | + [self setupTitleBgView]; | |
| 117 | + } | |
| 118 | +} | |
| 119 | +- (void)setupTitleBgView | |
| 120 | +{ | |
| 121 | + _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.sd_y, [UIScreen mainScreen].bounds.size.width, _titleLabel.sd_height + 20)]; | |
| 122 | + _bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3]; | |
| 123 | + [self.contentView addSubview:_bgView]; | |
| 124 | + [self.contentView insertSubview:_bgView atIndex:1]; | |
| 125 | +} | |
| 126 | +@end | |
| 127 | + | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/SDCycleScrollView.h
0 → 100644
| 1 | +// | |
| 2 | +// SDCycleScrollView.h | |
| 3 | +// SDCycleScrollView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-3-22. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/* | |
| 10 | + | |
| 11 | + ********************************************************************************* | |
| 12 | + * | |
| 13 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 14 | + * | |
| 15 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 16 | + * 帮您解决问题。 | |
| 17 | + * 新浪微博:GSD_iOS | |
| 18 | + * Email : gsdios@126.com | |
| 19 | + * GitHub: https://github.com/gsdios | |
| 20 | + * | |
| 21 | + * 另(我的自动布局库SDAutoLayout): | |
| 22 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 23 | + * 做最简单易用的AutoLayout库。 | |
| 24 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 25 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 26 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 27 | + ********************************************************************************* | |
| 28 | + | |
| 29 | + */ | |
| 30 | + | |
| 31 | +/* | |
| 32 | + * 当前版本为1.62 | |
| 33 | + * 更新日期:2016.04.21 | |
| 34 | + */ | |
| 35 | + | |
| 36 | +#import <UIKit/UIKit.h> | |
| 37 | + | |
| 38 | +typedef enum { | |
| 39 | + SDCycleScrollViewPageContolAlimentRight, | |
| 40 | + SDCycleScrollViewPageContolAlimentCenter | |
| 41 | +} SDCycleScrollViewPageContolAliment; | |
| 42 | + | |
| 43 | +typedef enum { | |
| 44 | + SDCycleScrollViewPageContolStyleClassic, // 系统自带经典样式 | |
| 45 | + SDCycleScrollViewPageContolStyleAnimated, // 动画效果pagecontrol | |
| 46 | + SDCycleScrollViewPageContolStyleNone // 不显示pagecontrol | |
| 47 | +} SDCycleScrollViewPageContolStyle; | |
| 48 | + | |
| 49 | +@class SDCycleScrollView; | |
| 50 | + | |
| 51 | +@protocol SDCycleScrollViewDelegate <NSObject> | |
| 52 | + | |
| 53 | +@optional | |
| 54 | + | |
| 55 | +/** 点击图片回调 */ | |
| 56 | +- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index; | |
| 57 | + | |
| 58 | +/** 图片滚动回调 */ | |
| 59 | +- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index; | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | +// 不需要自定义轮播cell的请忽略以下两个的代理方法 | |
| 67 | + | |
| 68 | +// ========== 轮播自定义cell ========== | |
| 69 | + | |
| 70 | +/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */ | |
| 71 | +- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view; | |
| 72 | + | |
| 73 | +/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的Nib。 */ | |
| 74 | +- (UINib *)customCollectionViewCellNibForCycleScrollView:(SDCycleScrollView *)view; | |
| 75 | + | |
| 76 | +/** 如果你自定义了cell样式,请在实现此代理方法为你的cell填充数据以及其它一系列设置 */ | |
| 77 | +- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view; | |
| 78 | + | |
| 79 | +@end | |
| 80 | + | |
| 81 | +@interface SDCycleScrollView : UIView | |
| 82 | + | |
| 83 | + | |
| 84 | +/** 初始轮播图(推荐使用) */ | |
| 85 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame delegate:(id<SDCycleScrollViewDelegate>)delegate placeholderImage:(UIImage *)placeholderImage; | |
| 86 | + | |
| 87 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageURLStringsGroup:(NSArray *)imageURLStringsGroup; | |
| 88 | + | |
| 89 | + | |
| 90 | +/** 本地图片轮播初始化方式 */ | |
| 91 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageNamesGroup:(NSArray *)imageNamesGroup; | |
| 92 | + | |
| 93 | +/** 本地图片轮播初始化方式2,infiniteLoop:是否无限循环 */ | |
| 94 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame shouldInfiniteLoop:(BOOL)infiniteLoop imageNamesGroup:(NSArray *)imageNamesGroup; | |
| 95 | + | |
| 96 | + | |
| 97 | +////////////////////// 数据源API ////////////////////// | |
| 98 | + | |
| 99 | +/** 网络图片 url string 数组 */ | |
| 100 | +@property (nonatomic, strong) NSArray *imageURLStringsGroup; | |
| 101 | + | |
| 102 | +/** 每张图片对应要显示的文字数组 */ | |
| 103 | +@property (nonatomic, strong) NSArray *titlesGroup; | |
| 104 | + | |
| 105 | +/** 本地图片数组 */ | |
| 106 | +@property (nonatomic, strong) NSArray *localizationImageNamesGroup; | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | +////////////////////// 滚动控制API ////////////////////// | |
| 113 | + | |
| 114 | +/** 自动滚动间隔时间,默认2s */ | |
| 115 | +@property (nonatomic, assign) CGFloat autoScrollTimeInterval; | |
| 116 | + | |
| 117 | +/** 是否无限循环,默认Yes */ | |
| 118 | +@property (nonatomic,assign) BOOL infiniteLoop; | |
| 119 | + | |
| 120 | +/** 是否自动滚动,默认Yes */ | |
| 121 | +@property (nonatomic,assign) BOOL autoScroll; | |
| 122 | + | |
| 123 | +/** 图片滚动方向,默认为水平滚动 */ | |
| 124 | +@property (nonatomic, assign) UICollectionViewScrollDirection scrollDirection; | |
| 125 | + | |
| 126 | +@property (nonatomic, weak) id<SDCycleScrollViewDelegate> delegate; | |
| 127 | + | |
| 128 | +/** block方式监听点击 */ | |
| 129 | +@property (nonatomic, copy) void (^clickItemOperationBlock)(NSInteger currentIndex); | |
| 130 | + | |
| 131 | +/** block方式监听滚动 */ | |
| 132 | +@property (nonatomic, copy) void (^itemDidScrollOperationBlock)(NSInteger currentIndex); | |
| 133 | + | |
| 134 | +/** 可以调用此方法手动控制滚动到哪一个index */ | |
| 135 | +- (void)makeScrollViewScrollToIndex:(NSInteger)index; | |
| 136 | + | |
| 137 | +/** 解决viewWillAppear时出现时轮播图卡在一半的问题,在控制器viewWillAppear时调用此方法 */ | |
| 138 | +- (void)adjustWhenControllerViewWillAppera; | |
| 139 | + | |
| 140 | +////////////////////// 自定义样式API ////////////////////// | |
| 141 | + | |
| 142 | +/** 轮播图片的ContentMode,默认为 UIViewContentModeScaleToFill */ | |
| 143 | +@property (nonatomic, assign) UIViewContentMode bannerImageViewContentMode; | |
| 144 | + | |
| 145 | +/** 占位图,用于网络未加载到图片时 */ | |
| 146 | +@property (nonatomic, strong) UIImage *placeholderImage; | |
| 147 | + | |
| 148 | +/** 是否显示分页控件 */ | |
| 149 | +@property (nonatomic, assign) BOOL showPageControl; | |
| 150 | + | |
| 151 | +/** 是否在只有一张图时隐藏pagecontrol,默认为YES */ | |
| 152 | +@property(nonatomic) BOOL hidesForSinglePage; | |
| 153 | + | |
| 154 | +/** 只展示文字轮播 */ | |
| 155 | +@property (nonatomic, assign) BOOL onlyDisplayText; | |
| 156 | + | |
| 157 | +/** pagecontrol 样式,默认为动画样式 */ | |
| 158 | +@property (nonatomic, assign) SDCycleScrollViewPageContolStyle pageControlStyle; | |
| 159 | + | |
| 160 | +/** 分页控件位置 */ | |
| 161 | +@property (nonatomic, assign) SDCycleScrollViewPageContolAliment pageControlAliment; | |
| 162 | + | |
| 163 | +/** 分页控件距离轮播图的底部间距(在默认间距基础上)的偏移量 */ | |
| 164 | +@property (nonatomic, assign) CGFloat pageControlBottomOffset; | |
| 165 | + | |
| 166 | +/** 分页控件距离轮播图的右边间距(在默认间距基础上)的偏移量 */ | |
| 167 | +@property (nonatomic, assign) CGFloat pageControlRightOffset; | |
| 168 | + | |
| 169 | +/** 分页控件小圆标大小 */ | |
| 170 | +@property (nonatomic, assign) CGSize pageControlDotSize; | |
| 171 | + | |
| 172 | +/** 当前分页控件小圆标颜色 */ | |
| 173 | +@property (nonatomic, strong) UIColor *currentPageDotColor; | |
| 174 | + | |
| 175 | +/** 其他分页控件小圆标颜色 */ | |
| 176 | +@property (nonatomic, strong) UIColor *pageDotColor; | |
| 177 | + | |
| 178 | +/** 当前分页控件小圆标图片 */ | |
| 179 | +@property (nonatomic, strong) UIImage *currentPageDotImage; | |
| 180 | + | |
| 181 | +/** 其他分页控件小圆标图片 */ | |
| 182 | +@property (nonatomic, strong) UIImage *pageDotImage; | |
| 183 | + | |
| 184 | +/** 轮播文字label字体颜色 */ | |
| 185 | +@property (nonatomic, strong) UIColor *titleLabelTextColor; | |
| 186 | + | |
| 187 | +/** 轮播文字label字体大小 */ | |
| 188 | +@property (nonatomic, strong) UIFont *titleLabelTextFont; | |
| 189 | + | |
| 190 | +/** 轮播文字label背景颜色 */ | |
| 191 | +@property (nonatomic, strong) UIColor *titleLabelBackgroundColor; | |
| 192 | + | |
| 193 | +/** 轮播文字label高度 */ | |
| 194 | +@property (nonatomic, assign) CGFloat titleLabelHeight; | |
| 195 | + | |
| 196 | +/** 轮播文字label对齐方式 */ | |
| 197 | +@property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment; | |
| 198 | + | |
| 199 | +/** 滚动手势禁用(文字轮播较实用) */ | |
| 200 | +- (void)disableScrollGesture; | |
| 201 | + | |
| 202 | + | |
| 203 | +////////////////////// 清除缓存API ////////////////////// | |
| 204 | + | |
| 205 | +/** 清除图片缓存(此次升级后统一使用SDWebImage管理图片加载和缓存) */ | |
| 206 | ++ (void)clearImagesCache; | |
| 207 | + | |
| 208 | +/** 清除图片缓存(兼容旧版本方法) */ | |
| 209 | +- (void)clearCache; | |
| 210 | + | |
| 211 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/SDCycleScrollView.m
0 → 100644
| 1 | +// | |
| 2 | +// SDCycleScrollView.m | |
| 3 | +// SDCycleScrollView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-3-22. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/* | |
| 10 | + | |
| 11 | + ********************************************************************************* | |
| 12 | + * | |
| 13 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 14 | + * | |
| 15 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 16 | + * 帮您解决问题。 | |
| 17 | + * 新浪微博:GSD_iOS | |
| 18 | + * Email : gsdios@126.com | |
| 19 | + * GitHub: https://github.com/gsdios | |
| 20 | + * | |
| 21 | + * 另(我的自动布局库SDAutoLayout): | |
| 22 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 23 | + * 做最简单易用的AutoLayout库。 | |
| 24 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 25 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 26 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 27 | + ********************************************************************************* | |
| 28 | + | |
| 29 | + */ | |
| 30 | + | |
| 31 | + | |
| 32 | +#import "SDCycleScrollView.h" | |
| 33 | +#import "SDCollectionViewCell.h" | |
| 34 | +#import "UIView+SDExtension.h" | |
| 35 | +#import "TAPageControl.h" | |
| 36 | +#import "SDWebImageManager.h" | |
| 37 | +#import "UIImageView+WebCache.h" | |
| 38 | + | |
| 39 | +#define kCycleScrollViewInitialPageControlDotSize CGSizeMake(10, 10) | |
| 40 | + | |
| 41 | +NSString * const ID = @"SDCycleScrollViewCell"; | |
| 42 | + | |
| 43 | +@interface SDCycleScrollView () <UICollectionViewDataSource, UICollectionViewDelegate> | |
| 44 | + | |
| 45 | + | |
| 46 | +@property (nonatomic, weak) UICollectionView *mainView; // 显示图片的collectionView | |
| 47 | +@property (nonatomic, weak) UICollectionViewFlowLayout *flowLayout; | |
| 48 | +@property (nonatomic, strong) NSArray *imagePathsGroup; | |
| 49 | +@property (nonatomic, weak) NSTimer *timer; | |
| 50 | +@property (nonatomic, assign) NSInteger totalItemsCount; | |
| 51 | +@property (nonatomic, weak) UIControl *pageControl; | |
| 52 | + | |
| 53 | +@property (nonatomic, strong) UIImageView *backgroundImageView; // 当imageURLs为空时的背景图 | |
| 54 | + | |
| 55 | +@end | |
| 56 | + | |
| 57 | +@implementation SDCycleScrollView | |
| 58 | + | |
| 59 | +- (instancetype)initWithFrame:(CGRect)frame | |
| 60 | +{ | |
| 61 | + if (self = [super initWithFrame:frame]) { | |
| 62 | + [self initialization]; | |
| 63 | + [self setupMainView]; | |
| 64 | + } | |
| 65 | + return self; | |
| 66 | +} | |
| 67 | + | |
| 68 | +- (void)awakeFromNib | |
| 69 | +{ | |
| 70 | + [super awakeFromNib]; | |
| 71 | + [self initialization]; | |
| 72 | + [self setupMainView]; | |
| 73 | +} | |
| 74 | + | |
| 75 | +- (void)initialization | |
| 76 | +{ | |
| 77 | + _pageControlAliment = SDCycleScrollViewPageContolAlimentCenter; | |
| 78 | + _autoScrollTimeInterval = 2.0; | |
| 79 | + _titleLabelTextColor = [UIColor whiteColor]; | |
| 80 | + _titleLabelTextFont= [UIFont systemFontOfSize:14]; | |
| 81 | + _titleLabelBackgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; | |
| 82 | + _titleLabelHeight = 30; | |
| 83 | + _titleLabelTextAlignment = NSTextAlignmentLeft; | |
| 84 | + _autoScroll = YES; | |
| 85 | + _infiniteLoop = YES; | |
| 86 | + _showPageControl = YES; | |
| 87 | + _pageControlDotSize = kCycleScrollViewInitialPageControlDotSize; | |
| 88 | + _pageControlBottomOffset = 0; | |
| 89 | + _pageControlRightOffset = 0; | |
| 90 | + _pageControlStyle = SDCycleScrollViewPageContolStyleClassic; | |
| 91 | + _hidesForSinglePage = YES; | |
| 92 | + _currentPageDotColor = [UIColor whiteColor]; | |
| 93 | + _pageDotColor = [UIColor lightGrayColor]; | |
| 94 | + _bannerImageViewContentMode = UIViewContentModeScaleToFill; | |
| 95 | + | |
| 96 | + self.backgroundColor = [UIColor lightGrayColor]; | |
| 97 | + | |
| 98 | +} | |
| 99 | + | |
| 100 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageNamesGroup:(NSArray *)imageNamesGroup | |
| 101 | +{ | |
| 102 | + SDCycleScrollView *cycleScrollView = [[self alloc] initWithFrame:frame]; | |
| 103 | + cycleScrollView.localizationImageNamesGroup = [NSMutableArray arrayWithArray:imageNamesGroup]; | |
| 104 | + return cycleScrollView; | |
| 105 | +} | |
| 106 | + | |
| 107 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame shouldInfiniteLoop:(BOOL)infiniteLoop imageNamesGroup:(NSArray *)imageNamesGroup | |
| 108 | +{ | |
| 109 | + SDCycleScrollView *cycleScrollView = [[self alloc] initWithFrame:frame]; | |
| 110 | + cycleScrollView.infiniteLoop = infiniteLoop; | |
| 111 | + cycleScrollView.localizationImageNamesGroup = [NSMutableArray arrayWithArray:imageNamesGroup]; | |
| 112 | + return cycleScrollView; | |
| 113 | +} | |
| 114 | + | |
| 115 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame imageURLStringsGroup:(NSArray *)imageURLsGroup | |
| 116 | +{ | |
| 117 | + SDCycleScrollView *cycleScrollView = [[self alloc] initWithFrame:frame]; | |
| 118 | + cycleScrollView.imageURLStringsGroup = [NSMutableArray arrayWithArray:imageURLsGroup]; | |
| 119 | + return cycleScrollView; | |
| 120 | +} | |
| 121 | + | |
| 122 | ++ (instancetype)cycleScrollViewWithFrame:(CGRect)frame delegate:(id<SDCycleScrollViewDelegate>)delegate placeholderImage:(UIImage *)placeholderImage | |
| 123 | +{ | |
| 124 | + SDCycleScrollView *cycleScrollView = [[self alloc] initWithFrame:frame]; | |
| 125 | + cycleScrollView.delegate = delegate; | |
| 126 | + cycleScrollView.placeholderImage = placeholderImage; | |
| 127 | + | |
| 128 | + return cycleScrollView; | |
| 129 | +} | |
| 130 | + | |
| 131 | +// 设置显示图片的collectionView | |
| 132 | +- (void)setupMainView | |
| 133 | +{ | |
| 134 | + UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; | |
| 135 | + flowLayout.minimumLineSpacing = 0; | |
| 136 | + flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; | |
| 137 | + _flowLayout = flowLayout; | |
| 138 | + | |
| 139 | + UICollectionView *mainView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout]; | |
| 140 | + mainView.backgroundColor = [UIColor clearColor]; | |
| 141 | + mainView.pagingEnabled = YES; | |
| 142 | + mainView.showsHorizontalScrollIndicator = NO; | |
| 143 | + mainView.showsVerticalScrollIndicator = NO; | |
| 144 | + [mainView registerClass:[SDCollectionViewCell class] forCellWithReuseIdentifier:ID]; | |
| 145 | + | |
| 146 | + mainView.dataSource = self; | |
| 147 | + mainView.delegate = self; | |
| 148 | + mainView.scrollsToTop = NO; | |
| 149 | + [self addSubview:mainView]; | |
| 150 | + _mainView = mainView; | |
| 151 | +} | |
| 152 | + | |
| 153 | + | |
| 154 | +#pragma mark - properties | |
| 155 | + | |
| 156 | +- (void)setDelegate:(id<SDCycleScrollViewDelegate>)delegate | |
| 157 | +{ | |
| 158 | + _delegate = delegate; | |
| 159 | + | |
| 160 | + if ([self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) { | |
| 161 | + [self.mainView registerClass:[self.delegate customCollectionViewCellClassForCycleScrollView:self] forCellWithReuseIdentifier:ID]; | |
| 162 | + }else if ([self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) { | |
| 163 | + [self.mainView registerNib:[self.delegate customCollectionViewCellNibForCycleScrollView:self] forCellWithReuseIdentifier:ID]; | |
| 164 | + } | |
| 165 | +} | |
| 166 | + | |
| 167 | +- (void)setPlaceholderImage:(UIImage *)placeholderImage | |
| 168 | +{ | |
| 169 | + _placeholderImage = placeholderImage; | |
| 170 | + | |
| 171 | + if (!self.backgroundImageView) { | |
| 172 | + UIImageView *bgImageView = [UIImageView new]; | |
| 173 | + bgImageView.contentMode = UIViewContentModeScaleAspectFit; | |
| 174 | + [self insertSubview:bgImageView belowSubview:self.mainView]; | |
| 175 | + self.backgroundImageView = bgImageView; | |
| 176 | + } | |
| 177 | + | |
| 178 | + self.backgroundImageView.image = placeholderImage; | |
| 179 | +} | |
| 180 | + | |
| 181 | +- (void)setPageControlDotSize:(CGSize)pageControlDotSize | |
| 182 | +{ | |
| 183 | + _pageControlDotSize = pageControlDotSize; | |
| 184 | + [self setupPageControl]; | |
| 185 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 186 | + TAPageControl *pageContol = (TAPageControl *)_pageControl; | |
| 187 | + pageContol.dotSize = pageControlDotSize; | |
| 188 | + } | |
| 189 | +} | |
| 190 | + | |
| 191 | +- (void)setShowPageControl:(BOOL)showPageControl | |
| 192 | +{ | |
| 193 | + _showPageControl = showPageControl; | |
| 194 | + | |
| 195 | + _pageControl.hidden = !showPageControl; | |
| 196 | +} | |
| 197 | + | |
| 198 | +- (void)setCurrentPageDotColor:(UIColor *)currentPageDotColor | |
| 199 | +{ | |
| 200 | + _currentPageDotColor = currentPageDotColor; | |
| 201 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 202 | + TAPageControl *pageControl = (TAPageControl *)_pageControl; | |
| 203 | + pageControl.dotColor = currentPageDotColor; | |
| 204 | + } else { | |
| 205 | + UIPageControl *pageControl = (UIPageControl *)_pageControl; | |
| 206 | + pageControl.currentPageIndicatorTintColor = currentPageDotColor; | |
| 207 | + } | |
| 208 | + | |
| 209 | +} | |
| 210 | + | |
| 211 | +- (void)setPageDotColor:(UIColor *)pageDotColor | |
| 212 | +{ | |
| 213 | + _pageDotColor = pageDotColor; | |
| 214 | + | |
| 215 | + if ([self.pageControl isKindOfClass:[UIPageControl class]]) { | |
| 216 | + UIPageControl *pageControl = (UIPageControl *)_pageControl; | |
| 217 | + pageControl.pageIndicatorTintColor = pageDotColor; | |
| 218 | + } | |
| 219 | +} | |
| 220 | + | |
| 221 | +- (void)setCurrentPageDotImage:(UIImage *)currentPageDotImage | |
| 222 | +{ | |
| 223 | + _currentPageDotImage = currentPageDotImage; | |
| 224 | + | |
| 225 | + if (self.pageControlStyle != SDCycleScrollViewPageContolStyleAnimated) { | |
| 226 | + self.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated; | |
| 227 | + } | |
| 228 | + | |
| 229 | + [self setCustomPageControlDotImage:currentPageDotImage isCurrentPageDot:YES]; | |
| 230 | +} | |
| 231 | + | |
| 232 | +- (void)setPageDotImage:(UIImage *)pageDotImage | |
| 233 | +{ | |
| 234 | + _pageDotImage = pageDotImage; | |
| 235 | + | |
| 236 | + if (self.pageControlStyle != SDCycleScrollViewPageContolStyleAnimated) { | |
| 237 | + self.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated; | |
| 238 | + } | |
| 239 | + | |
| 240 | + [self setCustomPageControlDotImage:pageDotImage isCurrentPageDot:NO]; | |
| 241 | +} | |
| 242 | + | |
| 243 | +- (void)setCustomPageControlDotImage:(UIImage *)image isCurrentPageDot:(BOOL)isCurrentPageDot | |
| 244 | +{ | |
| 245 | + if (!image || !self.pageControl) return; | |
| 246 | + | |
| 247 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 248 | + TAPageControl *pageControl = (TAPageControl *)_pageControl; | |
| 249 | + if (isCurrentPageDot) { | |
| 250 | + pageControl.currentDotImage = image; | |
| 251 | + } else { | |
| 252 | + pageControl.dotImage = image; | |
| 253 | + } | |
| 254 | + } | |
| 255 | +} | |
| 256 | + | |
| 257 | +- (void)setInfiniteLoop:(BOOL)infiniteLoop | |
| 258 | +{ | |
| 259 | + _infiniteLoop = infiniteLoop; | |
| 260 | + | |
| 261 | + if (self.imagePathsGroup.count) { | |
| 262 | + self.imagePathsGroup = self.imagePathsGroup; | |
| 263 | + } | |
| 264 | +} | |
| 265 | + | |
| 266 | +-(void)setAutoScroll:(BOOL)autoScroll{ | |
| 267 | + _autoScroll = autoScroll; | |
| 268 | + | |
| 269 | + [self invalidateTimer]; | |
| 270 | + | |
| 271 | + if (_autoScroll) { | |
| 272 | + [self setupTimer]; | |
| 273 | + } | |
| 274 | +} | |
| 275 | + | |
| 276 | +- (void)setScrollDirection:(UICollectionViewScrollDirection)scrollDirection | |
| 277 | +{ | |
| 278 | + _scrollDirection = scrollDirection; | |
| 279 | + | |
| 280 | + _flowLayout.scrollDirection = scrollDirection; | |
| 281 | +} | |
| 282 | + | |
| 283 | +- (void)setAutoScrollTimeInterval:(CGFloat)autoScrollTimeInterval | |
| 284 | +{ | |
| 285 | + _autoScrollTimeInterval = autoScrollTimeInterval; | |
| 286 | + | |
| 287 | + [self setAutoScroll:self.autoScroll]; | |
| 288 | +} | |
| 289 | + | |
| 290 | +- (void)setPageControlStyle:(SDCycleScrollViewPageContolStyle)pageControlStyle | |
| 291 | +{ | |
| 292 | + _pageControlStyle = pageControlStyle; | |
| 293 | + | |
| 294 | + [self setupPageControl]; | |
| 295 | +} | |
| 296 | + | |
| 297 | +- (void)setImagePathsGroup:(NSArray *)imagePathsGroup | |
| 298 | +{ | |
| 299 | + [self invalidateTimer]; | |
| 300 | + | |
| 301 | + _imagePathsGroup = imagePathsGroup; | |
| 302 | + | |
| 303 | + _totalItemsCount = self.infiniteLoop ? self.imagePathsGroup.count * 100 : self.imagePathsGroup.count; | |
| 304 | + | |
| 305 | + if (imagePathsGroup.count > 1) { // 由于 !=1 包含count == 0等情况 | |
| 306 | + self.mainView.scrollEnabled = YES; | |
| 307 | + [self setAutoScroll:self.autoScroll]; | |
| 308 | + } else { | |
| 309 | + self.mainView.scrollEnabled = NO; | |
| 310 | + [self invalidateTimer]; | |
| 311 | + } | |
| 312 | + | |
| 313 | + [self setupPageControl]; | |
| 314 | + [self.mainView reloadData]; | |
| 315 | +} | |
| 316 | + | |
| 317 | +- (void)setImageURLStringsGroup:(NSArray *)imageURLStringsGroup | |
| 318 | +{ | |
| 319 | + _imageURLStringsGroup = imageURLStringsGroup; | |
| 320 | + | |
| 321 | + NSMutableArray *temp = [NSMutableArray new]; | |
| 322 | + [_imageURLStringsGroup enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL * stop) { | |
| 323 | + NSString *urlString; | |
| 324 | + if ([obj isKindOfClass:[NSString class]]) { | |
| 325 | + urlString = obj; | |
| 326 | + } else if ([obj isKindOfClass:[NSURL class]]) { | |
| 327 | + NSURL *url = (NSURL *)obj; | |
| 328 | + urlString = [url absoluteString]; | |
| 329 | + } | |
| 330 | + if (urlString) { | |
| 331 | + [temp addObject:urlString]; | |
| 332 | + } | |
| 333 | + }]; | |
| 334 | + self.imagePathsGroup = [temp copy]; | |
| 335 | +} | |
| 336 | + | |
| 337 | +- (void)setLocalizationImageNamesGroup:(NSArray *)localizationImageNamesGroup | |
| 338 | +{ | |
| 339 | + _localizationImageNamesGroup = localizationImageNamesGroup; | |
| 340 | + self.imagePathsGroup = [localizationImageNamesGroup copy]; | |
| 341 | +} | |
| 342 | + | |
| 343 | +- (void)setTitlesGroup:(NSArray *)titlesGroup | |
| 344 | +{ | |
| 345 | + _titlesGroup = titlesGroup; | |
| 346 | + if (self.onlyDisplayText) { | |
| 347 | + NSMutableArray *temp = [NSMutableArray new]; | |
| 348 | + for (int i = 0; i < _titlesGroup.count; i++) { | |
| 349 | + [temp addObject:@""]; | |
| 350 | + } | |
| 351 | + self.backgroundColor = [UIColor clearColor]; | |
| 352 | + self.imageURLStringsGroup = [temp copy]; | |
| 353 | + } | |
| 354 | +} | |
| 355 | + | |
| 356 | +- (void)disableScrollGesture { | |
| 357 | + self.mainView.canCancelContentTouches = NO; | |
| 358 | + for (UIGestureRecognizer *gesture in self.mainView.gestureRecognizers) { | |
| 359 | + if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]) { | |
| 360 | + [self.mainView removeGestureRecognizer:gesture]; | |
| 361 | + } | |
| 362 | + } | |
| 363 | +} | |
| 364 | + | |
| 365 | +#pragma mark - actions | |
| 366 | + | |
| 367 | +- (void)setupTimer | |
| 368 | +{ | |
| 369 | + [self invalidateTimer]; // 创建定时器前先停止定时器,不然会出现僵尸定时器,导致轮播频率错误 | |
| 370 | + | |
| 371 | + NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:self.autoScrollTimeInterval target:self selector:@selector(automaticScroll) userInfo:nil repeats:YES]; | |
| 372 | + _timer = timer; | |
| 373 | + [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; | |
| 374 | +} | |
| 375 | + | |
| 376 | +- (void)invalidateTimer | |
| 377 | +{ | |
| 378 | + [_timer invalidate]; | |
| 379 | + _timer = nil; | |
| 380 | +} | |
| 381 | + | |
| 382 | +- (void)setupPageControl | |
| 383 | +{ | |
| 384 | + if (_pageControl) [_pageControl removeFromSuperview]; // 重新加载数据时调整 | |
| 385 | + | |
| 386 | + if (self.imagePathsGroup.count == 0 || self.onlyDisplayText) return; | |
| 387 | + | |
| 388 | + if ((self.imagePathsGroup.count == 1) && self.hidesForSinglePage) return; | |
| 389 | + | |
| 390 | + int indexOnPageControl = [self pageControlIndexWithCurrentCellIndex:[self currentIndex]]; | |
| 391 | + | |
| 392 | + switch (self.pageControlStyle) { | |
| 393 | + case SDCycleScrollViewPageContolStyleAnimated: | |
| 394 | + { | |
| 395 | + TAPageControl *pageControl = [[TAPageControl alloc] init]; | |
| 396 | + pageControl.numberOfPages = self.imagePathsGroup.count; | |
| 397 | + pageControl.dotColor = self.currentPageDotColor; | |
| 398 | + pageControl.userInteractionEnabled = NO; | |
| 399 | + pageControl.currentPage = indexOnPageControl; | |
| 400 | + [self addSubview:pageControl]; | |
| 401 | + _pageControl = pageControl; | |
| 402 | + } | |
| 403 | + break; | |
| 404 | + | |
| 405 | + case SDCycleScrollViewPageContolStyleClassic: | |
| 406 | + { | |
| 407 | + UIPageControl *pageControl = [[UIPageControl alloc] init]; | |
| 408 | + pageControl.numberOfPages = self.imagePathsGroup.count; | |
| 409 | + pageControl.currentPageIndicatorTintColor = self.currentPageDotColor; | |
| 410 | + pageControl.pageIndicatorTintColor = self.pageDotColor; | |
| 411 | + pageControl.userInteractionEnabled = NO; | |
| 412 | + pageControl.currentPage = indexOnPageControl; | |
| 413 | + [self addSubview:pageControl]; | |
| 414 | + _pageControl = pageControl; | |
| 415 | + } | |
| 416 | + break; | |
| 417 | + | |
| 418 | + default: | |
| 419 | + break; | |
| 420 | + } | |
| 421 | + | |
| 422 | + // 重设pagecontroldot图片 | |
| 423 | + if (self.currentPageDotImage) { | |
| 424 | + self.currentPageDotImage = self.currentPageDotImage; | |
| 425 | + } | |
| 426 | + if (self.pageDotImage) { | |
| 427 | + self.pageDotImage = self.pageDotImage; | |
| 428 | + } | |
| 429 | +} | |
| 430 | + | |
| 431 | + | |
| 432 | +- (void)automaticScroll | |
| 433 | +{ | |
| 434 | + if (0 == _totalItemsCount) return; | |
| 435 | + int currentIndex = [self currentIndex]; | |
| 436 | + int targetIndex = currentIndex + 1; | |
| 437 | + [self scrollToIndex:targetIndex]; | |
| 438 | +} | |
| 439 | + | |
| 440 | +- (void)scrollToIndex:(int)targetIndex | |
| 441 | +{ | |
| 442 | + if (targetIndex >= _totalItemsCount) { | |
| 443 | + if (self.infiniteLoop) { | |
| 444 | + targetIndex = _totalItemsCount * 0.5; | |
| 445 | + [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; | |
| 446 | + } | |
| 447 | + return; | |
| 448 | + } | |
| 449 | + [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES]; | |
| 450 | +} | |
| 451 | + | |
| 452 | +- (int)currentIndex | |
| 453 | +{ | |
| 454 | + if (_mainView.sd_width == 0 || _mainView.sd_height == 0) { | |
| 455 | + return 0; | |
| 456 | + } | |
| 457 | + | |
| 458 | + int index = 0; | |
| 459 | + if (_flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { | |
| 460 | + index = (_mainView.contentOffset.x + _flowLayout.itemSize.width * 0.5) / _flowLayout.itemSize.width; | |
| 461 | + } else { | |
| 462 | + index = (_mainView.contentOffset.y + _flowLayout.itemSize.height * 0.5) / _flowLayout.itemSize.height; | |
| 463 | + } | |
| 464 | + | |
| 465 | + return MAX(0, index); | |
| 466 | +} | |
| 467 | + | |
| 468 | +- (int)pageControlIndexWithCurrentCellIndex:(NSInteger)index | |
| 469 | +{ | |
| 470 | + return (int)index % self.imagePathsGroup.count; | |
| 471 | +} | |
| 472 | + | |
| 473 | +- (void)clearCache | |
| 474 | +{ | |
| 475 | + [[self class] clearImagesCache]; | |
| 476 | +} | |
| 477 | + | |
| 478 | ++ (void)clearImagesCache | |
| 479 | +{ | |
| 480 | + [[[SDWebImageManager sharedManager] imageCache] clearDiskOnCompletion:nil]; | |
| 481 | +} | |
| 482 | + | |
| 483 | +#pragma mark - life circles | |
| 484 | + | |
| 485 | +- (void)layoutSubviews | |
| 486 | +{ | |
| 487 | + self.delegate = self.delegate; | |
| 488 | + | |
| 489 | + [super layoutSubviews]; | |
| 490 | + | |
| 491 | + _flowLayout.itemSize = self.frame.size; | |
| 492 | + | |
| 493 | + _mainView.frame = self.bounds; | |
| 494 | + if (_mainView.contentOffset.x == 0 && _totalItemsCount) { | |
| 495 | + int targetIndex = 0; | |
| 496 | + if (self.infiniteLoop) { | |
| 497 | + targetIndex = _totalItemsCount * 0.5; | |
| 498 | + }else{ | |
| 499 | + targetIndex = 0; | |
| 500 | + } | |
| 501 | + [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; | |
| 502 | + } | |
| 503 | + | |
| 504 | + CGSize size = CGSizeZero; | |
| 505 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 506 | + TAPageControl *pageControl = (TAPageControl *)_pageControl; | |
| 507 | + if (!(self.pageDotImage && self.currentPageDotImage && CGSizeEqualToSize(kCycleScrollViewInitialPageControlDotSize, self.pageControlDotSize))) { | |
| 508 | + pageControl.dotSize = self.pageControlDotSize; | |
| 509 | + } | |
| 510 | + size = [pageControl sizeForNumberOfPages:self.imagePathsGroup.count]; | |
| 511 | + } else { | |
| 512 | + size = CGSizeMake(self.imagePathsGroup.count * self.pageControlDotSize.width * 1.5, self.pageControlDotSize.height); | |
| 513 | + } | |
| 514 | + CGFloat x = (self.sd_width - size.width) * 0.5; | |
| 515 | + if (self.pageControlAliment == SDCycleScrollViewPageContolAlimentRight) { | |
| 516 | + x = self.mainView.sd_width - size.width - 10; | |
| 517 | + } | |
| 518 | + CGFloat y = self.mainView.sd_height - size.height - 10; | |
| 519 | + | |
| 520 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 521 | + TAPageControl *pageControl = (TAPageControl *)_pageControl; | |
| 522 | + [pageControl sizeToFit]; | |
| 523 | + } | |
| 524 | + | |
| 525 | + CGRect pageControlFrame = CGRectMake(x, y, size.width, size.height); | |
| 526 | + pageControlFrame.origin.y -= self.pageControlBottomOffset; | |
| 527 | + pageControlFrame.origin.x -= self.pageControlRightOffset; | |
| 528 | + self.pageControl.frame = pageControlFrame; | |
| 529 | + self.pageControl.hidden = !_showPageControl; | |
| 530 | + | |
| 531 | + if (self.backgroundImageView) { | |
| 532 | + self.backgroundImageView.frame = self.bounds; | |
| 533 | + } | |
| 534 | + | |
| 535 | +} | |
| 536 | + | |
| 537 | +//解决当父View释放时,当前视图因为被Timer强引用而不能释放的问题 | |
| 538 | +- (void)willMoveToSuperview:(UIView *)newSuperview | |
| 539 | +{ | |
| 540 | + if (!newSuperview) { | |
| 541 | + [self invalidateTimer]; | |
| 542 | + } | |
| 543 | +} | |
| 544 | + | |
| 545 | +//解决当timer释放后 回调scrollViewDidScroll时访问野指针导致崩溃 | |
| 546 | +- (void)dealloc { | |
| 547 | + _mainView.delegate = nil; | |
| 548 | + _mainView.dataSource = nil; | |
| 549 | +} | |
| 550 | + | |
| 551 | +#pragma mark - public actions | |
| 552 | + | |
| 553 | +- (void)adjustWhenControllerViewWillAppera | |
| 554 | +{ | |
| 555 | + long targetIndex = [self currentIndex]; | |
| 556 | + if (targetIndex < _totalItemsCount) { | |
| 557 | + [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; | |
| 558 | + } | |
| 559 | +} | |
| 560 | + | |
| 561 | + | |
| 562 | +#pragma mark - UICollectionViewDataSource | |
| 563 | + | |
| 564 | +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section | |
| 565 | +{ | |
| 566 | + return _totalItemsCount; | |
| 567 | +} | |
| 568 | + | |
| 569 | +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath | |
| 570 | +{ | |
| 571 | + SDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; | |
| 572 | + | |
| 573 | + long itemIndex = [self pageControlIndexWithCurrentCellIndex:indexPath.item]; | |
| 574 | + | |
| 575 | + if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] && | |
| 576 | + [self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) { | |
| 577 | + [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self]; | |
| 578 | + return cell; | |
| 579 | + }else if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] && | |
| 580 | + [self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) { | |
| 581 | + [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self]; | |
| 582 | + return cell; | |
| 583 | + } | |
| 584 | + | |
| 585 | + NSString *imagePath = self.imagePathsGroup[itemIndex]; | |
| 586 | + | |
| 587 | + if (!self.onlyDisplayText && [imagePath isKindOfClass:[NSString class]]) { | |
| 588 | + if ([imagePath hasPrefix:@"http"]) { | |
| 589 | + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imagePath] placeholderImage:self.placeholderImage]; | |
| 590 | + } else { | |
| 591 | + UIImage *image = [UIImage imageNamed:imagePath]; | |
| 592 | + if (!image) { | |
| 593 | + image = [UIImage imageWithContentsOfFile:imagePath]; | |
| 594 | + } | |
| 595 | + cell.imageView.image = image; | |
| 596 | + } | |
| 597 | + } else if (!self.onlyDisplayText && [imagePath isKindOfClass:[UIImage class]]) { | |
| 598 | + cell.imageView.image = (UIImage *)imagePath; | |
| 599 | + } | |
| 600 | + | |
| 601 | + if (_titlesGroup.count && itemIndex < _titlesGroup.count) { | |
| 602 | + cell.title = _titlesGroup[itemIndex]; | |
| 603 | + } | |
| 604 | + | |
| 605 | + if (!cell.hasConfigured) { | |
| 606 | + cell.titleLabelBackgroundColor = self.titleLabelBackgroundColor; | |
| 607 | + cell.titleLabelHeight = self.titleLabelHeight; | |
| 608 | + cell.titleLabelTextAlignment = self.titleLabelTextAlignment; | |
| 609 | + cell.titleLabelTextColor = self.titleLabelTextColor; | |
| 610 | + cell.titleLabelTextFont = self.titleLabelTextFont; | |
| 611 | + cell.hasConfigured = YES; | |
| 612 | + cell.imageView.contentMode = self.bannerImageViewContentMode; | |
| 613 | + cell.clipsToBounds = YES; | |
| 614 | + cell.onlyDisplayText = self.onlyDisplayText; | |
| 615 | + } | |
| 616 | + | |
| 617 | + return cell; | |
| 618 | +} | |
| 619 | + | |
| 620 | +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath | |
| 621 | +{ | |
| 622 | + if ([self.delegate respondsToSelector:@selector(cycleScrollView:didSelectItemAtIndex:)]) { | |
| 623 | + [self.delegate cycleScrollView:self didSelectItemAtIndex:[self pageControlIndexWithCurrentCellIndex:indexPath.item]]; | |
| 624 | + } | |
| 625 | + if (self.clickItemOperationBlock) { | |
| 626 | + self.clickItemOperationBlock([self pageControlIndexWithCurrentCellIndex:indexPath.item]); | |
| 627 | + } | |
| 628 | +} | |
| 629 | + | |
| 630 | + | |
| 631 | +#pragma mark - UIScrollViewDelegate | |
| 632 | + | |
| 633 | +- (void)scrollViewDidScroll:(UIScrollView *)scrollView | |
| 634 | +{ | |
| 635 | + if (!self.imagePathsGroup.count) return; // 解决清除timer时偶尔会出现的问题 | |
| 636 | + int itemIndex = [self currentIndex]; | |
| 637 | + int indexOnPageControl = [self pageControlIndexWithCurrentCellIndex:itemIndex]; | |
| 638 | + | |
| 639 | + if ([self.pageControl isKindOfClass:[TAPageControl class]]) { | |
| 640 | + TAPageControl *pageControl = (TAPageControl *)_pageControl; | |
| 641 | + pageControl.currentPage = indexOnPageControl; | |
| 642 | + } else { | |
| 643 | + UIPageControl *pageControl = (UIPageControl *)_pageControl; | |
| 644 | + pageControl.currentPage = indexOnPageControl; | |
| 645 | + } | |
| 646 | +} | |
| 647 | + | |
| 648 | +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | |
| 649 | +{ | |
| 650 | + if (self.autoScroll) { | |
| 651 | + [self invalidateTimer]; | |
| 652 | + } | |
| 653 | +} | |
| 654 | + | |
| 655 | +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate | |
| 656 | +{ | |
| 657 | + if (self.autoScroll) { | |
| 658 | + [self setupTimer]; | |
| 659 | + } | |
| 660 | +} | |
| 661 | + | |
| 662 | +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | |
| 663 | +{ | |
| 664 | + [self scrollViewDidEndScrollingAnimation:self.mainView]; | |
| 665 | +} | |
| 666 | + | |
| 667 | +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView | |
| 668 | +{ | |
| 669 | + if (!self.imagePathsGroup.count) return; // 解决清除timer时偶尔会出现的问题 | |
| 670 | + int itemIndex = [self currentIndex]; | |
| 671 | + int indexOnPageControl = [self pageControlIndexWithCurrentCellIndex:itemIndex]; | |
| 672 | + | |
| 673 | + if ([self.delegate respondsToSelector:@selector(cycleScrollView:didScrollToIndex:)]) { | |
| 674 | + [self.delegate cycleScrollView:self didScrollToIndex:indexOnPageControl]; | |
| 675 | + } else if (self.itemDidScrollOperationBlock) { | |
| 676 | + self.itemDidScrollOperationBlock(indexOnPageControl); | |
| 677 | + } | |
| 678 | +} | |
| 679 | + | |
| 680 | +- (void)makeScrollViewScrollToIndex:(NSInteger)index{ | |
| 681 | + if (self.autoScroll) { | |
| 682 | + [self invalidateTimer]; | |
| 683 | + } | |
| 684 | + if (0 == _totalItemsCount) return; | |
| 685 | + | |
| 686 | + [self scrollToIndex:(int)(_totalItemsCount * 0.5 + index)]; | |
| 687 | + | |
| 688 | + if (self.autoScroll) { | |
| 689 | + [self setupTimer]; | |
| 690 | + } | |
| 691 | +} | |
| 692 | + | |
| 693 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/UIView+SDExtension.h
0 → 100644
| 1 | +// | |
| 2 | +// UIView+SDExtension.h | |
| 3 | +// SDRefreshView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-2-23. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/* | |
| 10 | + | |
| 11 | + ********************************************************************************* | |
| 12 | + * | |
| 13 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 14 | + * | |
| 15 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 16 | + * 帮您解决问题。 | |
| 17 | + * 新浪微博:GSD_iOS | |
| 18 | + * Email : gsdios@126.com | |
| 19 | + * GitHub: https://github.com/gsdios | |
| 20 | + * | |
| 21 | + * 另(我的自动布局库SDAutoLayout): | |
| 22 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 23 | + * 做最简单易用的AutoLayout库。 | |
| 24 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 25 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 26 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 27 | + ********************************************************************************* | |
| 28 | + | |
| 29 | + */ | |
| 30 | + | |
| 31 | +#import <UIKit/UIKit.h> | |
| 32 | + | |
| 33 | +#define SDColorCreater(r, g, b, a) [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:a] | |
| 34 | + | |
| 35 | + | |
| 36 | +@interface UIView (SDExtension) | |
| 37 | + | |
| 38 | +@property (nonatomic, assign) CGFloat sd_height; | |
| 39 | +@property (nonatomic, assign) CGFloat sd_width; | |
| 40 | + | |
| 41 | +@property (nonatomic, assign) CGFloat sd_y; | |
| 42 | +@property (nonatomic, assign) CGFloat sd_x; | |
| 43 | + | |
| 44 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/SDCycleScrollView/UIView+SDExtension.m
0 → 100644
| 1 | +// | |
| 2 | +// UIView+SDExtension.m | |
| 3 | +// SDRefreshView | |
| 4 | +// | |
| 5 | +// Created by aier on 15-2-23. | |
| 6 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/* | |
| 10 | + | |
| 11 | + ********************************************************************************* | |
| 12 | + * | |
| 13 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 14 | + * | |
| 15 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 16 | + * 帮您解决问题。 | |
| 17 | + * 新浪微博:GSD_iOS | |
| 18 | + * Email : gsdios@126.com | |
| 19 | + * GitHub: https://github.com/gsdios | |
| 20 | + * | |
| 21 | + * 另(我的自动布局库SDAutoLayout): | |
| 22 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 23 | + * 做最简单易用的AutoLayout库。 | |
| 24 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 25 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 26 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 27 | + ********************************************************************************* | |
| 28 | + | |
| 29 | + */ | |
| 30 | + | |
| 31 | +/* | |
| 32 | + | |
| 33 | + ********************************************************************************* | |
| 34 | + * | |
| 35 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 36 | + * 帮您解决问题。 | |
| 37 | + * 新浪微博:GSD_iOS | |
| 38 | + * Email : gsdios@126.com | |
| 39 | + * GitHub: https://github.com/gsdios | |
| 40 | + * | |
| 41 | + * 另(我的自动布局库SDAutoLayout): | |
| 42 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 43 | + * 做最简单易用的AutoLayout库。 | |
| 44 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 45 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 46 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 47 | + ********************************************************************************* | |
| 48 | + | |
| 49 | + */ | |
| 50 | + | |
| 51 | + | |
| 52 | +#import "UIView+SDExtension.h" | |
| 53 | + | |
| 54 | +@implementation UIView (SDExtension) | |
| 55 | + | |
| 56 | +- (CGFloat)sd_height | |
| 57 | +{ | |
| 58 | + return self.frame.size.height; | |
| 59 | +} | |
| 60 | + | |
| 61 | +- (void)setSd_height:(CGFloat)sd_height | |
| 62 | +{ | |
| 63 | + CGRect temp = self.frame; | |
| 64 | + temp.size.height = sd_height; | |
| 65 | + self.frame = temp; | |
| 66 | +} | |
| 67 | + | |
| 68 | +- (CGFloat)sd_width | |
| 69 | +{ | |
| 70 | + return self.frame.size.width; | |
| 71 | +} | |
| 72 | + | |
| 73 | +- (void)setSd_width:(CGFloat)sd_width | |
| 74 | +{ | |
| 75 | + CGRect temp = self.frame; | |
| 76 | + temp.size.width = sd_width; | |
| 77 | + self.frame = temp; | |
| 78 | +} | |
| 79 | + | |
| 80 | + | |
| 81 | +- (CGFloat)sd_y | |
| 82 | +{ | |
| 83 | + return self.frame.origin.y; | |
| 84 | +} | |
| 85 | + | |
| 86 | +- (void)setSd_y:(CGFloat)sd_y | |
| 87 | +{ | |
| 88 | + CGRect temp = self.frame; | |
| 89 | + temp.origin.y = sd_y; | |
| 90 | + self.frame = temp; | |
| 91 | +} | |
| 92 | + | |
| 93 | +- (CGFloat)sd_x | |
| 94 | +{ | |
| 95 | + return self.frame.origin.x; | |
| 96 | +} | |
| 97 | + | |
| 98 | +- (void)setSd_x:(CGFloat)sd_x | |
| 99 | +{ | |
| 100 | + CGRect temp = self.frame; | |
| 101 | + temp.origin.x = sd_x; | |
| 102 | + self.frame = temp; | |
| 103 | +} | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | +@end | ... | ... |
Podfile
README.md
| 1 | +SDCycleScrollView -> SDCollectionViewCell.m | |
| 2 | + | |
| 3 | +// | |
| 4 | +// SDCollectionViewCell.m | |
| 5 | +// SDCycleScrollView | |
| 6 | +// | |
| 7 | +// Created by aier on 15-3-22. | |
| 8 | +// Copyright (c) 2015年 GSD. All rights reserved. | |
| 9 | +// | |
| 10 | + | |
| 11 | + | |
| 12 | +/* | |
| 13 | + | |
| 14 | + ********************************************************************************* | |
| 15 | + * | |
| 16 | + * 🌟🌟🌟 新建SDCycleScrollView交流QQ群:185534916 🌟🌟🌟 | |
| 17 | + * | |
| 18 | + * 在您使用此自动轮播库的过程中如果出现bug请及时以以下任意一种方式联系我们,我们会及时修复bug并 | |
| 19 | + * 帮您解决问题。 | |
| 20 | + * 新浪微博:GSD_iOS | |
| 21 | + * Email : gsdios@126.com | |
| 22 | + * GitHub: https://github.com/gsdios | |
| 23 | + * | |
| 24 | + * 另(我的自动布局库SDAutoLayout): | |
| 25 | + * 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于 | |
| 26 | + * 做最简单易用的AutoLayout库。 | |
| 27 | + * 视频教程:http://www.letv.com/ptv/vplay/24038772.html | |
| 28 | + * 用法示例:https://github.com/gsdios/SDAutoLayout/blob/master/README.md | |
| 29 | + * GitHub:https://github.com/gsdios/SDAutoLayout | |
| 30 | + ********************************************************************************* | |
| 31 | + | |
| 32 | + */ | |
| 33 | + | |
| 34 | + | |
| 35 | +#import "SDCollectionViewCell.h" | |
| 36 | +#import "UIView+SDExtension.h" | |
| 37 | + | |
| 38 | +@implementation SDCollectionViewCell | |
| 39 | +{ | |
| 40 | + __weak UILabel *_titleLabel; | |
| 41 | + UIView *_bgView; | |
| 42 | + | |
| 43 | +} | |
| 44 | + | |
| 45 | + | |
| 46 | +- (instancetype)initWithFrame:(CGRect)frame | |
| 47 | +{ | |
| 48 | + if (self = [super initWithFrame:frame]) { | |
| 49 | + [self setupImageView]; | |
| 50 | + [self setupTitleLabel]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return self; | |
| 54 | +} | |
| 55 | + | |
| 56 | +- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor | |
| 57 | +{ | |
| 58 | + _titleLabelBackgroundColor = titleLabelBackgroundColor; | |
| 59 | + _titleLabel.backgroundColor = titleLabelBackgroundColor; | |
| 60 | +} | |
| 61 | + | |
| 62 | +- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor | |
| 63 | +{ | |
| 64 | + _titleLabelTextColor = titleLabelTextColor; | |
| 65 | + _titleLabel.textColor = titleLabelTextColor; | |
| 66 | +} | |
| 67 | + | |
| 68 | +- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont | |
| 69 | +{ | |
| 70 | + _titleLabelTextFont = titleLabelTextFont; | |
| 71 | + _titleLabel.font = titleLabelTextFont; | |
| 72 | +} | |
| 73 | + | |
| 74 | +- (void)setupImageView | |
| 75 | +{ | |
| 76 | + UIImageView *imageView = [[UIImageView alloc] init]; | |
| 77 | + _imageView = imageView; | |
| 78 | + [self.contentView addSubview:imageView]; | |
| 79 | +} | |
| 80 | + | |
| 81 | +- (void)setupTitleLabel | |
| 82 | +{ | |
| 83 | + UILabel *titleLabel = [[UILabel alloc] init]; | |
| 84 | + titleLabel.numberOfLines = 2; | |
| 85 | + _titleLabel = titleLabel; | |
| 86 | + _titleLabel.hidden = YES; | |
| 87 | + [self.contentView addSubview:titleLabel]; | |
| 88 | +} | |
| 89 | + | |
| 90 | +- (void)setTitle:(NSString *)title | |
| 91 | +{ | |
| 92 | + _title = [title copy]; | |
| 93 | + _titleLabel.text = [NSString stringWithFormat:@" %@", title]; | |
| 94 | + if (_titleLabel.hidden) { | |
| 95 | + _titleLabel.hidden = NO; | |
| 96 | + } | |
| 97 | +} | |
| 98 | + | |
| 99 | +-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment | |
| 100 | +{ | |
| 101 | + _titleLabelTextAlignment = titleLabelTextAlignment; | |
| 102 | + _titleLabel.textAlignment = titleLabelTextAlignment; | |
| 103 | +} | |
| 104 | + | |
| 105 | +- (void)layoutSubviews | |
| 106 | +{ | |
| 107 | + [super layoutSubviews]; | |
| 108 | + | |
| 109 | + if (self.onlyDisplayText) { | |
| 110 | + _titleLabel.frame = self.bounds; | |
| 111 | + } else { | |
| 112 | + _imageView.frame = self.bounds; | |
| 113 | + CGFloat titleLabelW = self.sd_width; | |
| 114 | + CGFloat titleLabelH = _titleLabelHeight; | |
| 115 | + CGFloat titleLabelX = 10; | |
| 116 | + CGFloat titleLabelY = self.sd_height - titleLabelH-20; | |
| 117 | + _titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW-2*titleLabelX, titleLabelH); | |
| 118 | + [self setupTitleBgView]; | |
| 119 | + } | |
| 120 | +} | |
| 121 | +- (void)setupTitleBgView | |
| 122 | +{ | |
| 123 | + _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.sd_y, [UIScreen mainScreen].bounds.size.width, _titleLabel.sd_height + 20)]; | |
| 124 | + _bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3]; | |
| 125 | + [self.contentView addSubview:_bgView]; | |
| 126 | + [self.contentView insertSubview:_bgView atIndex:1]; | |
| 127 | +} | |
| 128 | +@end | |
| 129 | + | |
| 130 | + | ... | ... |