Skip to content

Commit

Permalink
add UITableViewIndexSearch type
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingJourney committed Feb 25, 2018
1 parent 547810c commit 20ed08f
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 236 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ toast效果图:
2. 当滑动UITableView列表时,另一根手指再滑动索引视图,列表滑动事件失效;
3. 当滑动索引视图时,会有指示器或者toast提示当前索引位置;
4. 当滑动索引视图时,不可以点击或者滑动UITableView列表;
5. 可以任意定制指示器、toast、索引视图的大小,文字颜色大小,间距等UI样式。
5. 可以任意定制指示器、toast、索引视图的大小,文字颜色大小,间距等UI样式;
6. 当第一个数据为UITableViewIndexSearch时,自动添加放大镜图标。

# 使用方法
可以通过CocoaPods导入,支持iOS7及以上。
Expand Down
4 changes: 2 additions & 2 deletions SCIndexView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|

s.name = "SCIndexView"
s.version = "2.0.3"
s.version = "2.1.0"
s.summary = "SCIndexView provide a index view."
s.description = "SCIndexView provide a index view like Wechat. It is very easy."

Expand All @@ -20,7 +20,7 @@ Pod::Spec.new do |s|

s.platform = :ios, "7.0"

s.source = { :git => "https://github.com/TalkingJourney/SCIndexView.git", :tag => "2.0.3" }
s.source = { :git => "https://github.com/TalkingJourney/SCIndexView.git", :tag => "2.1.0" }

s.source_files = "SCIndexView/**/*.{h,m}"
s.public_header_files = "SCIndexView/**/*.h"
Expand Down
192 changes: 134 additions & 58 deletions SCIndexView/SCIndexView.m

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SCIndexView/SCIndexViewConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import <UIKit/UIKit.h>

extern const NSUInteger SCIndexViewInvalidSection;
extern const NSInteger SCIndexViewSearchSection;

typedef NS_ENUM(NSUInteger, SCIndexViewStyle) {
SCIndexViewStyleDefault = 0, // 指向点
Expand Down
3 changes: 2 additions & 1 deletion SCIndexView/SCIndexViewConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "SCIndexViewConfiguration.h"

const NSUInteger SCIndexViewInvalidSection = NSUIntegerMax - 1;
const NSInteger SCIndexViewSearchSection = -1;

static inline UIColor *SCGetColor(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)
{
Expand Down Expand Up @@ -65,7 +66,7 @@ + (instancetype)configurationWithIndexViewStyle:(SCIndexViewStyle)indexViewStyle
indexItemSelectedTextColor:[UIColor whiteColor]
indexItemHeight:15
indexItemRightMargin:5
indexItemsSpace:5];
indexItemsSpace:0];
}

+ (instancetype)configurationWithIndexViewStyle:(SCIndexViewStyle)indexViewStyle
Expand Down
16 changes: 5 additions & 11 deletions SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
1A3B567F2009F2D30073C98F /* YYClassInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B567C2009F2D30073C98F /* YYClassInfo.m */; };
B874C548200A53CB0040DA53 /* SCIndexViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B874C547200A53CB0040DA53 /* SCIndexViewController.m */; };
B874C54E200F83770040DA53 /* UITableView+SCIndexView.m in Sources */ = {isa = PBXBuildFile; fileRef = B874C54D200F83770040DA53 /* UITableView+SCIndexView.m */; };
B874C551200F9BE30040DA53 /* SCIndexView2Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = B874C550200F9BE30040DA53 /* SCIndexView2Controller.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -51,8 +50,6 @@
B874C547200A53CB0040DA53 /* SCIndexViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SCIndexViewController.m; sourceTree = "<group>"; };
B874C54C200F83770040DA53 /* UITableView+SCIndexView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UITableView+SCIndexView.h"; sourceTree = "<group>"; };
B874C54D200F83770040DA53 /* UITableView+SCIndexView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UITableView+SCIndexView.m"; sourceTree = "<group>"; };
B874C54F200F9BE30040DA53 /* SCIndexView2Controller.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SCIndexView2Controller.h; sourceTree = "<group>"; };
B874C550200F9BE30040DA53 /* SCIndexView2Controller.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SCIndexView2Controller.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -96,8 +93,6 @@
1A3B56452009EE370073C98F /* ViewController.m */,
B874C546200A53CB0040DA53 /* SCIndexViewController.h */,
B874C547200A53CB0040DA53 /* SCIndexViewController.m */,
B874C54F200F9BE30040DA53 /* SCIndexView2Controller.h */,
B874C550200F9BE30040DA53 /* SCIndexView2Controller.m */,
1A3B56472009EE370073C98F /* Main.storyboard */,
1A3B564A2009EE370073C98F /* Assets.xcassets */,
1A3B564C2009EE370073C98F /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -164,7 +159,7 @@
TargetAttributes = {
1A3B563D2009EE370073C98F = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
ProvisioningStyle = Manual;
};
};
};
Expand Down Expand Up @@ -207,7 +202,6 @@
files = (
1A3B56772009F0B40073C98F /* SectionItem.m in Sources */,
1A3B56462009EE370073C98F /* ViewController.m in Sources */,
B874C551200F9BE30040DA53 /* SCIndexView2Controller.m in Sources */,
1A3B567E2009F2D30073C98F /* NSObject+YYModel.m in Sources */,
B874C54E200F83770040DA53 /* UITableView+SCIndexView.m in Sources */,
1A3B56512009EE370073C98F /* main.m in Sources */,
Expand Down Expand Up @@ -350,8 +344,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 3J3Z9KKCQS;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SCIndexViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -367,8 +361,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 3J3Z9KKCQS;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SCIndexViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
9 changes: 0 additions & 9 deletions SCIndexViewDemo/SCIndexViewDemo/SCIndexView2Controller.h

This file was deleted.

121 changes: 0 additions & 121 deletions SCIndexViewDemo/SCIndexViewDemo/SCIndexView2Controller.m

This file was deleted.

1 change: 1 addition & 0 deletions SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
@interface SCIndexViewController : UIViewController

@property (nonatomic, assign) SCIndexViewStyle indexViewStyle;
@property (nonatomic, assign) BOOL hasSearch;

@end
44 changes: 18 additions & 26 deletions SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#import "SCIndexViewController.h"
#import "YYModel.h"
#import "SectionItem.h"
#import "SCIndexView.h"
#import "UITableView+SCIndexView.h"

@interface SCIndexViewController () <UITableViewDataSource, UITableViewDelegate, SCIndexViewDelegate>
@interface SCIndexViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) SCIndexView *indexView;

@property (nonatomic, copy) NSArray<SectionItem *> *tableViewDataSource;
@property (nonatomic, assign) BOOL translucent;
Expand All @@ -23,13 +22,13 @@ - (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
switch (self.indexViewStyle) {
case SCIndexViewStyleDefault:
self.title = @"指向点类型 V1.x";
self.title = @"指向点类型";
break;

case SCIndexViewStyleCenterToast:
self.title = @"中心提示弹层 V1.x";
self.title = @"中心提示弹层";
break;

default:
break;
}
Expand All @@ -38,7 +37,6 @@ - (void)viewDidLoad {
self.translucent = YES;

[self.view addSubview:self.tableView];
[self.view addSubview:self.indexView];

dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Indexes" ofType:@"plist"];
Expand All @@ -52,7 +50,10 @@ - (void)viewDidLoad {
self.tableViewDataSource = tableViewDataSource.copy;
[self.tableView reloadData];

self.indexView.dataSource = indexViewDataSource.copy;
if (self.hasSearch) {
[indexViewDataSource insertObject:UITableViewIndexSearch atIndex:0];
}
self.tableView.sc_indexViewDataSource = indexViewDataSource.copy;
});
});
}
Expand Down Expand Up @@ -91,13 +92,6 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
return sectionItem.title;
}

#pragma mark - SCIndexViewDelegate

- (void)indexView:(SCIndexView *)indexView didSelectAtSection:(NSUInteger)section
{

}

#pragma mark - Event Response

- (void)onActionWithRightBarButton
Expand All @@ -118,18 +112,16 @@ - (UITableView *)tableView
_tableView.dataSource = self;
_tableView.delegate = self;
[_tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"cell"];

if (self.hasSearch) {
self.tableView.tableHeaderView = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)];
}

SCIndexViewConfiguration *configuration = [SCIndexViewConfiguration configurationWithIndexViewStyle:self.indexViewStyle];
_tableView.sc_indexViewConfiguration = configuration;
_tableView.sc_translucentForTableViewInNavigationBar = self.translucent;
}
return _tableView;
}

- (SCIndexView *)indexView
{
if (!_indexView) {
_indexView = [[SCIndexView alloc] initWithTableView:self.tableView configuration:[SCIndexViewConfiguration configurationWithIndexViewStyle:self.indexViewStyle]];
_indexView.translucentForTableViewInNavigationBar = self.translucent;
_indexView.delegate = self;
}
return _indexView;
}

@end
Loading

0 comments on commit 20ed08f

Please sign in to comment.