DCScrollView 是 UIScrollView 的扩展,可滚动内容,标题像 Etsy iOS 应用程序一样延迟滚动。
在项目中使用此功能有两种方式
将 DCScrollView/*.{h.m}
复制到您的项目中
使用 CocoaPods 安装并编写 Podfile
platform :ios
pod 'DCScrollView', '~> 1.1.0'
DCScrollView 使用了一种简单的策略。它定义了一个委托和一个数据源,客户端实现。DCScrollViewDelegate 和 DCScrollViewDataSource 与 UITableViewDelegate 和 UITableViewDataSource 类似。
重置单元格并重新显示可见单元格。当前页面在重新加载后保持可见。
- (void)reloadData;
如果 UIViewController 接收到内存警告,则控制 DCScrollView 清除其拥有的内存。
- (void)clearData;
DCScrollView.h
DCScrollViewDataSource
和 DCScrollViewDelegate
方法
#import "DCScrollView.h"
@interface ExampleViewController ()
<DCScrollViewDataSource, DCScrollViewDelegate>
@end
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
DCScrollView *scrollView = [[DCScrollView alloc]initWithFrame:self.view.bounds];
scrollView.dataSource = self;
scrollView.delegate = self;
}
- (NSInteger)numberOfCellsInDCScrollView:(DCScrollView *)scrollView
{
return 10;
}
- (DCScrollViewCell *)dcscrollView:(DCScrollView *)scrollView cellAtIndex:(NSInteger)index
{
NSString *identifier = @"Cell";
DCScrollViewCell *cell = [scrollView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[DCScrollViewCell alloc] initWithReuseIdentifier:identifier];
}
return cell;
}
- (NSString *)titleOfDCScrollViewCellAtIndex:(NSInteger)index
{
return @"title";
}
- (void)setFont:(UIFont *)font textColor:(UIColor *)textColor highlightedTextColor:(UIColor *)highlightedTextColor
DCScrollView 可在 MIT 许可证下使用。