├── .gitignore ├── FDSlideBar.podspec ├── FDSlideBarDemo ├── FDSlideBarDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── FDSlideBarDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── FDSlideBar │ │ ├── FDSlideBar.h │ │ ├── FDSlideBar.m │ │ ├── FDSlideBarItem.h │ │ └── FDSlideBarItem.m │ ├── FDSlideContentView.h │ ├── FDSlideContentView.m │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ ├── controllers(deprecated) │ │ ├── NewsViewController.h │ │ ├── NewsViewController.m │ │ ├── NewsViewController.xib │ │ ├── ViewController.h │ │ └── ViewController.m │ └── main.m ├── FDSlideBarDemoTests │ ├── FDSlideBarDemoTests.m │ └── Info.plist ├── TableViewCell.h ├── TableViewCell.m └── TableViewCell.xib ├── LICENSE ├── README.md ├── ScreenShot ├── one.png └── two.png └── 效果.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | *.DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | #Pods/ 28 | -------------------------------------------------------------------------------- /FDSlideBar.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint FDAlertView.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "FDSlideBar" 19 | s.version = "0.0.1" 20 | s.summary = "A custom slide bar like the top slide menu of NTES news client used in iOS." 21 | 22 | s.description = <<-DESC 23 | FDSlideBar is a sliding bar which is muck like the top menu bar of NTES news client. it can scroll the bar and content automaticly with smoth animation. It uses block to receive your deal when you select a itme or scroll the content view to previous or next page. It also support you to set some style such as backgroundColor, font size, text color, selected font size and selected text color and so on. Now I achieve the content by using table view. so it will benefit much from table view, there will be no memory problem and the original animation will surpport better. 24 | 25 | * Think: Why did you write this? What is the focus? What does it do? 26 | * CocoaPods will be using this to generate tags, and improve search results. 27 | * Try to keep it short, snappy and to the point. 28 | * Finally, don't worry about the indent, CocoaPods strips it! 29 | DESC 30 | 31 | s.homepage = "https://github.com/fergusding/FDSlideBar" 32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 33 | 34 | 35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 36 | # 37 | # Licensing your code is important. See http://choosealicense.com for more info. 38 | # CocoaPods will detect a license file if there is a named LICENSE* 39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 40 | # 41 | 42 | s.license = "MIT" 43 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 44 | 45 | 46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 47 | # 48 | # Specify the authors of the library, with email addresses. Email addresses 49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 50 | # accepts just a name if you'd rather not provide an email address. 51 | # 52 | # Specify a social_media_url where others can refer to, for example a twitter 53 | # profile URL. 54 | # 55 | 56 | s.author = { "Fergus Ding" => "fergusding@augmentum.com.cn" } 57 | # Or just: s.author = "Fergus Ding" 58 | # s.authors = { "Fergus Ding" => "fergusding@augmentum.com.cn" } 59 | # s.social_media_url = "http://twitter.com/Fergus Ding" 60 | 61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 62 | # 63 | # If this Pod runs only on iOS or OS X, then specify the platform and 64 | # the deployment target. You can optionally include the target after the platform. 65 | # 66 | 67 | # s.platform = :ios 68 | s.platform = :ios, "7.0" 69 | 70 | # When using multiple platforms 71 | # s.ios.deployment_target = "5.0" 72 | # s.osx.deployment_target = "10.7" 73 | 74 | 75 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 76 | # 77 | # Specify the location from where the source should be retrieved. 78 | # Supports git, hg, bzr, svn and HTTP. 79 | # 80 | 81 | s.source = { :git => "https://github.com/fergusding/FDSlideBar.git", :tag => "0.0.1" } 82 | 83 | 84 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 85 | # 86 | # CocoaPods is smart about how it includes source code. For source files 87 | # giving a folder will include any h, m, mm, c & cpp files. For header 88 | # files it will include any header in the folder. 89 | # Not including the public_header_files will make all headers public. 90 | # 91 | 92 | s.source_files = "FDSlideBar/*" 93 | # s.exclude_files = "Classes/Exclude" 94 | 95 | # s.public_header_files = "Classes/**/*.h" 96 | 97 | 98 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 99 | # 100 | # A list of resources included with the Pod. These are copied into the 101 | # target bundle with a build phase script. Anything else will be cleaned. 102 | # You can preserve files from being cleaned, please don't preserve 103 | # non-essential files like tests, examples and documentation. 104 | # 105 | 106 | # s.resource = "icon.png" 107 | # s.resources = "Resources/*.png" 108 | 109 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 110 | 111 | 112 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 113 | # 114 | # Link your library with frameworks, or libraries. Libraries do not include 115 | # the lib prefix of their name. 116 | # 117 | 118 | # s.framework = "SomeFramework" 119 | s.frameworks = "Foundation", "UIKit" 120 | 121 | # s.library = "iconv" 122 | # s.libraries = "iconv", "xml2" 123 | 124 | 125 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 126 | # 127 | # If your library depends on compiler flags you can set them in the xcconfig hash 128 | # where they will only apply to your library. If you depend on other Podspecs 129 | # you can include multiple dependencies to ensure it works. 130 | 131 | s.requires_arc = true 132 | 133 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 134 | # s.dependency "JSONKit", "~> 1.4" 135 | 136 | end 137 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | EA23932B1B43E38C0021FB0D /* FDSlideContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = EA23932A1B43E38C0021FB0D /* FDSlideContentView.m */; }; 11 | EA2A49341B54F6DD00064186 /* TableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = EA2A49321B54F6DD00064186 /* TableViewCell.m */; }; 12 | EA2A49351B54F6DD00064186 /* TableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA2A49331B54F6DD00064186 /* TableViewCell.xib */; }; 13 | EA30E73A1B2034C1000A8291 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EA30E7391B2034C1000A8291 /* main.m */; }; 14 | EA30E73D1B2034C1000A8291 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EA30E73C1B2034C1000A8291 /* AppDelegate.m */; }; 15 | EA30E7431B2034C1000A8291 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA30E7411B2034C1000A8291 /* Main.storyboard */; }; 16 | EA30E7451B2034C1000A8291 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EA30E7441B2034C1000A8291 /* Images.xcassets */; }; 17 | EA30E7481B2034C1000A8291 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = EA30E7461B2034C1000A8291 /* LaunchScreen.xib */; }; 18 | EA30E7541B2034C1000A8291 /* FDSlideBarDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EA30E7531B2034C1000A8291 /* FDSlideBarDemoTests.m */; }; 19 | EA30E7601B203524000A8291 /* FDSlideBar.m in Sources */ = {isa = PBXBuildFile; fileRef = EA30E75F1B203524000A8291 /* FDSlideBar.m */; }; 20 | EA30E7631B203543000A8291 /* FDSlideBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = EA30E7621B203543000A8291 /* FDSlideBarItem.m */; }; 21 | EA8AD9F31B54AE98007802CF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8AD9F21B54AE98007802CF /* ViewController.m */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | EA30E74E1B2034C1000A8291 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = EA30E72C1B2034C1000A8291 /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = EA30E7331B2034C1000A8291; 30 | remoteInfo = FDSlideBarDemo; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | EA2393291B43E38C0021FB0D /* FDSlideContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDSlideContentView.h; sourceTree = ""; }; 36 | EA23932A1B43E38C0021FB0D /* FDSlideContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDSlideContentView.m; sourceTree = ""; }; 37 | EA2A49311B54F6DD00064186 /* TableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewCell.h; sourceTree = SOURCE_ROOT; }; 38 | EA2A49321B54F6DD00064186 /* TableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewCell.m; sourceTree = SOURCE_ROOT; }; 39 | EA2A49331B54F6DD00064186 /* TableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableViewCell.xib; sourceTree = SOURCE_ROOT; }; 40 | EA30E7341B2034C1000A8291 /* FDSlideBarDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FDSlideBarDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | EA30E7381B2034C1000A8291 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | EA30E7391B2034C1000A8291 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | EA30E73B1B2034C1000A8291 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | EA30E73C1B2034C1000A8291 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | EA30E7421B2034C1000A8291 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | EA30E7441B2034C1000A8291 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 47 | EA30E7471B2034C1000A8291 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 48 | EA30E74D1B2034C1000A8291 /* FDSlideBarDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FDSlideBarDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | EA30E7521B2034C1000A8291 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | EA30E7531B2034C1000A8291 /* FDSlideBarDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FDSlideBarDemoTests.m; sourceTree = ""; }; 51 | EA30E75E1B203524000A8291 /* FDSlideBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FDSlideBar.h; path = FDSlideBar/FDSlideBar.h; sourceTree = ""; }; 52 | EA30E75F1B203524000A8291 /* FDSlideBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FDSlideBar.m; path = FDSlideBar/FDSlideBar.m; sourceTree = ""; }; 53 | EA30E7611B203543000A8291 /* FDSlideBarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FDSlideBarItem.h; path = FDSlideBar/FDSlideBarItem.h; sourceTree = ""; }; 54 | EA30E7621B203543000A8291 /* FDSlideBarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FDSlideBarItem.m; path = FDSlideBar/FDSlideBarItem.m; sourceTree = ""; }; 55 | EA8AD9F11B54AE98007802CF /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 56 | EA8AD9F21B54AE98007802CF /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | EA30E7311B2034C1000A8291 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | EA30E74A1B2034C1000A8291 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | EA30E72B1B2034C1000A8291 = { 78 | isa = PBXGroup; 79 | children = ( 80 | EA30E7361B2034C1000A8291 /* FDSlideBarDemo */, 81 | EA30E7501B2034C1000A8291 /* FDSlideBarDemoTests */, 82 | EA30E7351B2034C1000A8291 /* Products */, 83 | ); 84 | sourceTree = ""; 85 | }; 86 | EA30E7351B2034C1000A8291 /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | EA30E7341B2034C1000A8291 /* FDSlideBarDemo.app */, 90 | EA30E74D1B2034C1000A8291 /* FDSlideBarDemoTests.xctest */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | EA30E7361B2034C1000A8291 /* FDSlideBarDemo */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | EA30E75D1B2034D5000A8291 /* FDSlideBar */, 99 | EA30E73B1B2034C1000A8291 /* AppDelegate.h */, 100 | EA30E73C1B2034C1000A8291 /* AppDelegate.m */, 101 | EA8AD9F11B54AE98007802CF /* ViewController.h */, 102 | EA8AD9F21B54AE98007802CF /* ViewController.m */, 103 | EA2A49311B54F6DD00064186 /* TableViewCell.h */, 104 | EA2A49321B54F6DD00064186 /* TableViewCell.m */, 105 | EA2A49331B54F6DD00064186 /* TableViewCell.xib */, 106 | EA30E7411B2034C1000A8291 /* Main.storyboard */, 107 | EA30E7441B2034C1000A8291 /* Images.xcassets */, 108 | EA30E7461B2034C1000A8291 /* LaunchScreen.xib */, 109 | EA30E7371B2034C1000A8291 /* Supporting Files */, 110 | ); 111 | path = FDSlideBarDemo; 112 | sourceTree = ""; 113 | }; 114 | EA30E7371B2034C1000A8291 /* Supporting Files */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | EA30E7381B2034C1000A8291 /* Info.plist */, 118 | EA30E7391B2034C1000A8291 /* main.m */, 119 | ); 120 | name = "Supporting Files"; 121 | sourceTree = ""; 122 | }; 123 | EA30E7501B2034C1000A8291 /* FDSlideBarDemoTests */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | EA30E7531B2034C1000A8291 /* FDSlideBarDemoTests.m */, 127 | EA30E7511B2034C1000A8291 /* Supporting Files */, 128 | ); 129 | path = FDSlideBarDemoTests; 130 | sourceTree = ""; 131 | }; 132 | EA30E7511B2034C1000A8291 /* Supporting Files */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | EA30E7521B2034C1000A8291 /* Info.plist */, 136 | ); 137 | name = "Supporting Files"; 138 | sourceTree = ""; 139 | }; 140 | EA30E75D1B2034D5000A8291 /* FDSlideBar */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | EA30E75E1B203524000A8291 /* FDSlideBar.h */, 144 | EA30E75F1B203524000A8291 /* FDSlideBar.m */, 145 | EA30E7611B203543000A8291 /* FDSlideBarItem.h */, 146 | EA30E7621B203543000A8291 /* FDSlideBarItem.m */, 147 | EA2393291B43E38C0021FB0D /* FDSlideContentView.h */, 148 | EA23932A1B43E38C0021FB0D /* FDSlideContentView.m */, 149 | ); 150 | name = FDSlideBar; 151 | sourceTree = ""; 152 | }; 153 | /* End PBXGroup section */ 154 | 155 | /* Begin PBXNativeTarget section */ 156 | EA30E7331B2034C1000A8291 /* FDSlideBarDemo */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = EA30E7571B2034C1000A8291 /* Build configuration list for PBXNativeTarget "FDSlideBarDemo" */; 159 | buildPhases = ( 160 | EA30E7301B2034C1000A8291 /* Sources */, 161 | EA30E7311B2034C1000A8291 /* Frameworks */, 162 | EA30E7321B2034C1000A8291 /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | ); 168 | name = FDSlideBarDemo; 169 | productName = FDSlideBarDemo; 170 | productReference = EA30E7341B2034C1000A8291 /* FDSlideBarDemo.app */; 171 | productType = "com.apple.product-type.application"; 172 | }; 173 | EA30E74C1B2034C1000A8291 /* FDSlideBarDemoTests */ = { 174 | isa = PBXNativeTarget; 175 | buildConfigurationList = EA30E75A1B2034C1000A8291 /* Build configuration list for PBXNativeTarget "FDSlideBarDemoTests" */; 176 | buildPhases = ( 177 | EA30E7491B2034C1000A8291 /* Sources */, 178 | EA30E74A1B2034C1000A8291 /* Frameworks */, 179 | EA30E74B1B2034C1000A8291 /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | EA30E74F1B2034C1000A8291 /* PBXTargetDependency */, 185 | ); 186 | name = FDSlideBarDemoTests; 187 | productName = FDSlideBarDemoTests; 188 | productReference = EA30E74D1B2034C1000A8291 /* FDSlideBarDemoTests.xctest */; 189 | productType = "com.apple.product-type.bundle.unit-test"; 190 | }; 191 | /* End PBXNativeTarget section */ 192 | 193 | /* Begin PBXProject section */ 194 | EA30E72C1B2034C1000A8291 /* Project object */ = { 195 | isa = PBXProject; 196 | attributes = { 197 | LastUpgradeCheck = 0630; 198 | ORGANIZATIONNAME = fergusding; 199 | TargetAttributes = { 200 | EA30E7331B2034C1000A8291 = { 201 | CreatedOnToolsVersion = 6.3.1; 202 | }; 203 | EA30E74C1B2034C1000A8291 = { 204 | CreatedOnToolsVersion = 6.3.1; 205 | TestTargetID = EA30E7331B2034C1000A8291; 206 | }; 207 | }; 208 | }; 209 | buildConfigurationList = EA30E72F1B2034C1000A8291 /* Build configuration list for PBXProject "FDSlideBarDemo" */; 210 | compatibilityVersion = "Xcode 3.2"; 211 | developmentRegion = English; 212 | hasScannedForEncodings = 0; 213 | knownRegions = ( 214 | en, 215 | Base, 216 | ); 217 | mainGroup = EA30E72B1B2034C1000A8291; 218 | productRefGroup = EA30E7351B2034C1000A8291 /* Products */; 219 | projectDirPath = ""; 220 | projectRoot = ""; 221 | targets = ( 222 | EA30E7331B2034C1000A8291 /* FDSlideBarDemo */, 223 | EA30E74C1B2034C1000A8291 /* FDSlideBarDemoTests */, 224 | ); 225 | }; 226 | /* End PBXProject section */ 227 | 228 | /* Begin PBXResourcesBuildPhase section */ 229 | EA30E7321B2034C1000A8291 /* Resources */ = { 230 | isa = PBXResourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | EA30E7431B2034C1000A8291 /* Main.storyboard in Resources */, 234 | EA2A49351B54F6DD00064186 /* TableViewCell.xib in Resources */, 235 | EA30E7481B2034C1000A8291 /* LaunchScreen.xib in Resources */, 236 | EA30E7451B2034C1000A8291 /* Images.xcassets in Resources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | EA30E74B1B2034C1000A8291 /* Resources */ = { 241 | isa = PBXResourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | /* End PBXResourcesBuildPhase section */ 248 | 249 | /* Begin PBXSourcesBuildPhase section */ 250 | EA30E7301B2034C1000A8291 /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | EA2A49341B54F6DD00064186 /* TableViewCell.m in Sources */, 255 | EA23932B1B43E38C0021FB0D /* FDSlideContentView.m in Sources */, 256 | EA8AD9F31B54AE98007802CF /* ViewController.m in Sources */, 257 | EA30E73D1B2034C1000A8291 /* AppDelegate.m in Sources */, 258 | EA30E73A1B2034C1000A8291 /* main.m in Sources */, 259 | EA30E7631B203543000A8291 /* FDSlideBarItem.m in Sources */, 260 | EA30E7601B203524000A8291 /* FDSlideBar.m in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | EA30E7491B2034C1000A8291 /* Sources */ = { 265 | isa = PBXSourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | EA30E7541B2034C1000A8291 /* FDSlideBarDemoTests.m in Sources */, 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | /* End PBXSourcesBuildPhase section */ 273 | 274 | /* Begin PBXTargetDependency section */ 275 | EA30E74F1B2034C1000A8291 /* PBXTargetDependency */ = { 276 | isa = PBXTargetDependency; 277 | target = EA30E7331B2034C1000A8291 /* FDSlideBarDemo */; 278 | targetProxy = EA30E74E1B2034C1000A8291 /* PBXContainerItemProxy */; 279 | }; 280 | /* End PBXTargetDependency section */ 281 | 282 | /* Begin PBXVariantGroup section */ 283 | EA30E7411B2034C1000A8291 /* Main.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | EA30E7421B2034C1000A8291 /* Base */, 287 | ); 288 | name = Main.storyboard; 289 | sourceTree = ""; 290 | }; 291 | EA30E7461B2034C1000A8291 /* LaunchScreen.xib */ = { 292 | isa = PBXVariantGroup; 293 | children = ( 294 | EA30E7471B2034C1000A8291 /* Base */, 295 | ); 296 | name = LaunchScreen.xib; 297 | sourceTree = ""; 298 | }; 299 | /* End PBXVariantGroup section */ 300 | 301 | /* Begin XCBuildConfiguration section */ 302 | EA30E7551B2034C1000A8291 /* Debug */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ALWAYS_SEARCH_USER_PATHS = NO; 306 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 307 | CLANG_CXX_LIBRARY = "libc++"; 308 | CLANG_ENABLE_MODULES = YES; 309 | CLANG_ENABLE_OBJC_ARC = YES; 310 | CLANG_WARN_BOOL_CONVERSION = YES; 311 | CLANG_WARN_CONSTANT_CONVERSION = YES; 312 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 313 | CLANG_WARN_EMPTY_BODY = YES; 314 | CLANG_WARN_ENUM_CONVERSION = YES; 315 | CLANG_WARN_INT_CONVERSION = YES; 316 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 317 | CLANG_WARN_UNREACHABLE_CODE = YES; 318 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 319 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 320 | COPY_PHASE_STRIP = NO; 321 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 322 | ENABLE_STRICT_OBJC_MSGSEND = YES; 323 | GCC_C_LANGUAGE_STANDARD = gnu99; 324 | GCC_DYNAMIC_NO_PIC = NO; 325 | GCC_NO_COMMON_BLOCKS = YES; 326 | GCC_OPTIMIZATION_LEVEL = 0; 327 | GCC_PREPROCESSOR_DEFINITIONS = ( 328 | "DEBUG=1", 329 | "$(inherited)", 330 | ); 331 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 332 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 333 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 334 | GCC_WARN_UNDECLARED_SELECTOR = YES; 335 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 336 | GCC_WARN_UNUSED_FUNCTION = YES; 337 | GCC_WARN_UNUSED_VARIABLE = YES; 338 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 339 | MTL_ENABLE_DEBUG_INFO = YES; 340 | ONLY_ACTIVE_ARCH = YES; 341 | SDKROOT = iphoneos; 342 | TARGETED_DEVICE_FAMILY = "1,2"; 343 | }; 344 | name = Debug; 345 | }; 346 | EA30E7561B2034C1000A8291 /* Release */ = { 347 | isa = XCBuildConfiguration; 348 | buildSettings = { 349 | ALWAYS_SEARCH_USER_PATHS = NO; 350 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 351 | CLANG_CXX_LIBRARY = "libc++"; 352 | CLANG_ENABLE_MODULES = YES; 353 | CLANG_ENABLE_OBJC_ARC = YES; 354 | CLANG_WARN_BOOL_CONVERSION = YES; 355 | CLANG_WARN_CONSTANT_CONVERSION = YES; 356 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 357 | CLANG_WARN_EMPTY_BODY = YES; 358 | CLANG_WARN_ENUM_CONVERSION = YES; 359 | CLANG_WARN_INT_CONVERSION = YES; 360 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 361 | CLANG_WARN_UNREACHABLE_CODE = YES; 362 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 363 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 364 | COPY_PHASE_STRIP = NO; 365 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 366 | ENABLE_NS_ASSERTIONS = NO; 367 | ENABLE_STRICT_OBJC_MSGSEND = YES; 368 | GCC_C_LANGUAGE_STANDARD = gnu99; 369 | GCC_NO_COMMON_BLOCKS = YES; 370 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 371 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 372 | GCC_WARN_UNDECLARED_SELECTOR = YES; 373 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 374 | GCC_WARN_UNUSED_FUNCTION = YES; 375 | GCC_WARN_UNUSED_VARIABLE = YES; 376 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 377 | MTL_ENABLE_DEBUG_INFO = NO; 378 | SDKROOT = iphoneos; 379 | TARGETED_DEVICE_FAMILY = "1,2"; 380 | VALIDATE_PRODUCT = YES; 381 | }; 382 | name = Release; 383 | }; 384 | EA30E7581B2034C1000A8291 /* Debug */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 388 | INFOPLIST_FILE = FDSlideBarDemo/Info.plist; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | }; 392 | name = Debug; 393 | }; 394 | EA30E7591B2034C1000A8291 /* Release */ = { 395 | isa = XCBuildConfiguration; 396 | buildSettings = { 397 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 398 | INFOPLIST_FILE = FDSlideBarDemo/Info.plist; 399 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 400 | PRODUCT_NAME = "$(TARGET_NAME)"; 401 | }; 402 | name = Release; 403 | }; 404 | EA30E75B1B2034C1000A8291 /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | buildSettings = { 407 | BUNDLE_LOADER = "$(TEST_HOST)"; 408 | FRAMEWORK_SEARCH_PATHS = ( 409 | "$(SDKROOT)/Developer/Library/Frameworks", 410 | "$(inherited)", 411 | ); 412 | GCC_PREPROCESSOR_DEFINITIONS = ( 413 | "DEBUG=1", 414 | "$(inherited)", 415 | ); 416 | INFOPLIST_FILE = FDSlideBarDemoTests/Info.plist; 417 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 418 | PRODUCT_NAME = "$(TARGET_NAME)"; 419 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FDSlideBarDemo.app/FDSlideBarDemo"; 420 | }; 421 | name = Debug; 422 | }; 423 | EA30E75C1B2034C1000A8291 /* Release */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | BUNDLE_LOADER = "$(TEST_HOST)"; 427 | FRAMEWORK_SEARCH_PATHS = ( 428 | "$(SDKROOT)/Developer/Library/Frameworks", 429 | "$(inherited)", 430 | ); 431 | INFOPLIST_FILE = FDSlideBarDemoTests/Info.plist; 432 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FDSlideBarDemo.app/FDSlideBarDemo"; 435 | }; 436 | name = Release; 437 | }; 438 | /* End XCBuildConfiguration section */ 439 | 440 | /* Begin XCConfigurationList section */ 441 | EA30E72F1B2034C1000A8291 /* Build configuration list for PBXProject "FDSlideBarDemo" */ = { 442 | isa = XCConfigurationList; 443 | buildConfigurations = ( 444 | EA30E7551B2034C1000A8291 /* Debug */, 445 | EA30E7561B2034C1000A8291 /* Release */, 446 | ); 447 | defaultConfigurationIsVisible = 0; 448 | defaultConfigurationName = Release; 449 | }; 450 | EA30E7571B2034C1000A8291 /* Build configuration list for PBXNativeTarget "FDSlideBarDemo" */ = { 451 | isa = XCConfigurationList; 452 | buildConfigurations = ( 453 | EA30E7581B2034C1000A8291 /* Debug */, 454 | EA30E7591B2034C1000A8291 /* Release */, 455 | ); 456 | defaultConfigurationIsVisible = 0; 457 | defaultConfigurationName = Release; 458 | }; 459 | EA30E75A1B2034C1000A8291 /* Build configuration list for PBXNativeTarget "FDSlideBarDemoTests" */ = { 460 | isa = XCConfigurationList; 461 | buildConfigurations = ( 462 | EA30E75B1B2034C1000A8291 /* Debug */, 463 | EA30E75C1B2034C1000A8291 /* Release */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | /* End XCConfigurationList section */ 469 | }; 470 | rootObject = EA30E72C1B2034C1000A8291 /* Project object */; 471 | } 472 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideBar/FDSlideBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideBar.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^FDSlideBarItemSelectedCallback)(NSUInteger idx); 12 | 13 | @interface FDSlideBar : UIView 14 | 15 | // All the titles of FDSilderBar 16 | @property (copy, nonatomic) NSArray *itemsTitle; 17 | 18 | // All the item's text color of the normal state 19 | @property (strong, nonatomic) UIColor *itemColor; 20 | 21 | // The selected item's text color 22 | @property (strong, nonatomic) UIColor *itemSelectedColor; 23 | 24 | // The slider color 25 | @property (strong, nonatomic) UIColor *sliderColor; 26 | 27 | // Add the callback deal when a slide bar item be selected 28 | - (void)slideBarItemSelectedCallback:(FDSlideBarItemSelectedCallback)callback; 29 | 30 | // Set the slide bar item at index to be selected 31 | - (void)selectSlideBarItemAtIndex:(NSUInteger)index; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideBar/FDSlideBar.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideBar.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "FDSlideBar.h" 10 | #import "FDSlideBarItem.h" 11 | 12 | #define DEVICE_WIDTH CGRectGetWidth([UIScreen mainScreen].bounds) 13 | #define DEFAULT_SLIDER_COLOR [UIColor orangeColor] 14 | #define SLIDER_VIEW_HEIGHT 2 15 | 16 | @interface FDSlideBar () 17 | 18 | @property (strong, nonatomic) UIScrollView *scrollView; 19 | @property (strong, nonatomic) NSMutableArray *items; 20 | @property (strong, nonatomic) UIView *sliderView; 21 | 22 | @property (strong, nonatomic) FDSlideBarItem *selectedItem; 23 | @property (strong, nonatomic) FDSlideBarItemSelectedCallback callback; 24 | 25 | @end 26 | 27 | @implementation FDSlideBar 28 | 29 | #pragma mark - Lifecircle 30 | 31 | - (instancetype)init { 32 | CGRect frame = CGRectMake(0, 20, DEVICE_WIDTH, 46); 33 | return [self initWithFrame:frame]; 34 | } 35 | 36 | - (instancetype)initWithFrame:(CGRect)frame { 37 | if (self= [super initWithFrame:frame]) { 38 | _items = [NSMutableArray array]; 39 | [self initScrollView]; 40 | [self initSliderView]; 41 | } 42 | return self; 43 | } 44 | 45 | #pragma - mark Custom Accessors 46 | 47 | - (void)setItemsTitle:(NSArray *)itemsTitle { 48 | _itemsTitle = itemsTitle; 49 | [self setupItems]; 50 | } 51 | 52 | - (void)setItemColor:(UIColor *)itemColor { 53 | for (FDSlideBarItem *item in _items) { 54 | [item setItemTitleColor:itemColor]; 55 | } 56 | } 57 | 58 | - (void)setItemSelectedColor:(UIColor *)itemSelectedColor { 59 | for (FDSlideBarItem *item in _items) { 60 | [item setItemSelectedTitleColor:itemSelectedColor]; 61 | } 62 | } 63 | 64 | - (void)setSliderColor:(UIColor *)sliderColor { 65 | _sliderColor = sliderColor; 66 | self.sliderView.backgroundColor = _sliderColor; 67 | } 68 | 69 | - (void)setSelectedItem:(FDSlideBarItem *)selectedItem { 70 | _selectedItem.selected = NO; 71 | _selectedItem = selectedItem; 72 | } 73 | 74 | 75 | #pragma - mark Private 76 | 77 | - (void)initScrollView { 78 | _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 79 | _scrollView.backgroundColor = [UIColor clearColor]; 80 | _scrollView.showsHorizontalScrollIndicator = NO; 81 | _scrollView.showsVerticalScrollIndicator = NO; 82 | _scrollView.bounces = NO; 83 | [self addSubview:_scrollView]; 84 | } 85 | 86 | - (void)initSliderView { 87 | _sliderView = [[UIView alloc] init]; 88 | _sliderColor = DEFAULT_SLIDER_COLOR; 89 | _sliderView.backgroundColor = _sliderColor; 90 | [_scrollView addSubview:_sliderView]; 91 | } 92 | 93 | - (void)setupItems { 94 | CGFloat itemX = 0; 95 | for (NSString *title in _itemsTitle) { 96 | FDSlideBarItem *item = [[FDSlideBarItem alloc] init]; 97 | item.delegate = self; 98 | 99 | // Init the current item's frame 100 | CGFloat itemW = [FDSlideBarItem widthForTitle:title]; 101 | item.frame = CGRectMake(itemX, 0, itemW, CGRectGetHeight(_scrollView.frame)); 102 | [item setItemTitle:title]; 103 | [_items addObject:item]; 104 | 105 | [_scrollView addSubview:item]; 106 | 107 | // Caculate the origin.x of the next item 108 | itemX = CGRectGetMaxX(item.frame); 109 | } 110 | 111 | // Cculate the scrollView 's contentSize by all the items 112 | _scrollView.contentSize = CGSizeMake(itemX, CGRectGetHeight(_scrollView.frame)); 113 | 114 | // Set the default selected item, the first item 115 | FDSlideBarItem *firstItem = [self.items firstObject]; 116 | firstItem.selected = YES; 117 | _selectedItem = firstItem; 118 | 119 | // Set the frame of sliderView by the selected item 120 | _sliderView.frame = CGRectMake(0, self.frame.size.height - SLIDER_VIEW_HEIGHT, firstItem.frame.size.width, SLIDER_VIEW_HEIGHT); 121 | } 122 | 123 | - (void)scrollToVisibleItem:(FDSlideBarItem *)item { 124 | NSInteger selectedItemIndex = [self.items indexOfObject:_selectedItem]; 125 | NSInteger visibleItemIndex = [self.items indexOfObject:item]; 126 | 127 | // If the selected item is same to the item to be visible, nothing to do 128 | if (selectedItemIndex == visibleItemIndex) { 129 | return; 130 | } 131 | 132 | CGPoint offset = _scrollView.contentOffset; 133 | 134 | // If the item to be visible is in the screen, nothing to do 135 | if (CGRectGetMinX(item.frame) >= offset.x && CGRectGetMaxX(item.frame) <= (offset.x + CGRectGetWidth(_scrollView.frame))) { 136 | return; 137 | } 138 | 139 | // Update the scrollView's contentOffset according to different situation 140 | if (selectedItemIndex < visibleItemIndex) { 141 | // The item to be visible is on the right of the selected item and the selected item is out of screeen by the left, also the opposite case, set the offset respectively 142 | if (CGRectGetMaxX(_selectedItem.frame) < offset.x) { 143 | offset.x = CGRectGetMinX(item.frame); 144 | } else { 145 | offset.x = CGRectGetMaxX(item.frame) - CGRectGetWidth(_scrollView.frame); 146 | } 147 | } else { 148 | // The item to be visible is on the left of the selected item and the selected item is out of screeen by the right, also the opposite case, set the offset respectively 149 | if (CGRectGetMinX(_selectedItem.frame) > (offset.x + CGRectGetWidth(_scrollView.frame))) { 150 | offset.x = CGRectGetMaxX(item.frame) - CGRectGetWidth(_scrollView.frame); 151 | } else { 152 | offset.x = CGRectGetMinX(item.frame); 153 | } 154 | } 155 | _scrollView.contentOffset = offset; 156 | } 157 | 158 | - (void)addAnimationWithSelectedItem:(FDSlideBarItem *)item { 159 | // Caculate the distance of translation 160 | CGFloat dx = CGRectGetMidX(item.frame) - CGRectGetMidX(_selectedItem.frame); 161 | 162 | // Add the animation about translation 163 | CABasicAnimation *positionAnimation = [CABasicAnimation animation]; 164 | positionAnimation.keyPath = @"position.x"; 165 | positionAnimation.fromValue = @(_sliderView.layer.position.x); 166 | positionAnimation.toValue = @(_sliderView.layer.position.x + dx); 167 | 168 | // Add the animation about size 169 | CABasicAnimation *boundsAnimation = [CABasicAnimation animation]; 170 | boundsAnimation.keyPath = @"bounds.size.width"; 171 | boundsAnimation.fromValue = @(CGRectGetWidth(_sliderView.layer.bounds)); 172 | boundsAnimation.toValue = @(CGRectGetWidth(item.frame)); 173 | 174 | // Combine all the animations to a group 175 | CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; 176 | animationGroup.animations = @[positionAnimation, boundsAnimation]; 177 | animationGroup.duration = 0.2; 178 | [_sliderView.layer addAnimation:animationGroup forKey:@"basic"]; 179 | 180 | // Keep the state after animating 181 | _sliderView.layer.position = CGPointMake(_sliderView.layer.position.x + dx, _sliderView.layer.position.y); 182 | CGRect rect = _sliderView.layer.bounds; 183 | rect.size.width = CGRectGetWidth(item.frame); 184 | _sliderView.layer.bounds = rect; 185 | } 186 | 187 | #pragma mark - Public 188 | 189 | - (void)slideBarItemSelectedCallback:(FDSlideBarItemSelectedCallback)callback { 190 | _callback = callback; 191 | } 192 | 193 | - (void)selectSlideBarItemAtIndex:(NSUInteger)index { 194 | FDSlideBarItem *item = [self.items objectAtIndex:index]; 195 | if (item == _selectedItem) { 196 | return; 197 | } 198 | 199 | item.selected = YES; 200 | [self scrollToVisibleItem:item]; 201 | [self addAnimationWithSelectedItem:item]; 202 | self.selectedItem = item; 203 | } 204 | 205 | #pragma mark - FDSlideBarItemDelegate 206 | 207 | - (void)slideBarItemSelected:(FDSlideBarItem *)item { 208 | if (item == _selectedItem) { 209 | return; 210 | } 211 | 212 | [self scrollToVisibleItem:item]; 213 | [self addAnimationWithSelectedItem:item]; 214 | self.selectedItem = item; 215 | _callback([self.items indexOfObject:item]); 216 | } 217 | 218 | @end 219 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideBar/FDSlideBarItem.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideBarItem.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol FDSlideBarItemDelegate; 12 | 13 | @interface FDSlideBarItem : UIView 14 | 15 | @property (assign, nonatomic) BOOL selected; 16 | @property (weak, nonatomic) id delegate; 17 | 18 | - (void)setItemTitle:(NSString *)title; 19 | - (void)setItemTitleFont:(CGFloat)fontSize; 20 | - (void)setItemTitleColor:(UIColor *)color; 21 | - (void)setItemSelectedTileFont:(CGFloat)fontSize; 22 | - (void)setItemSelectedTitleColor:(UIColor *)color; 23 | 24 | + (CGFloat)widthForTitle:(NSString *)title; 25 | 26 | @end 27 | 28 | @protocol FDSlideBarItemDelegate 29 | 30 | - (void)slideBarItemSelected:(FDSlideBarItem *)item; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideBar/FDSlideBarItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideBarItem.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "FDSlideBarItem.h" 10 | 11 | #define DEFAULT_TITLE_FONTSIZE 15 12 | #define DEFAULT_TITLE_SELECTED_FONTSIZE 17 13 | #define DEFAULT_TITLE_COLOR [UIColor blackColor] 14 | #define DEFAULT_TITLE_SELECTED_COLOR [UIColor orangeColor] 15 | 16 | #define HORIZONTAL_MARGIN 10 17 | 18 | @interface FDSlideBarItem () 19 | 20 | @property (copy, nonatomic) NSString *title; 21 | @property (assign, nonatomic) CGFloat fontSize; 22 | @property (assign, nonatomic) CGFloat selectedFontSize; 23 | @property (strong, nonatomic) UIColor *color; 24 | @property (strong, nonatomic) UIColor *selectedColor; 25 | 26 | @end 27 | 28 | @implementation FDSlideBarItem 29 | 30 | #pragma mark - Lifecircle 31 | 32 | - (instancetype) init { 33 | if (self = [super init]) { 34 | _fontSize = DEFAULT_TITLE_FONTSIZE; 35 | _selectedFontSize = DEFAULT_TITLE_SELECTED_FONTSIZE; 36 | _color = DEFAULT_TITLE_COLOR; 37 | _selectedColor = DEFAULT_TITLE_SELECTED_COLOR; 38 | 39 | self.backgroundColor = [UIColor clearColor]; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)drawRect:(CGRect)rect { 45 | CGFloat titleX = (CGRectGetWidth(self.frame) - [self titleSize].width) * 0.5; 46 | CGFloat titleY = (CGRectGetHeight(self.frame) - [self titleSize].height) * 0.5; 47 | 48 | CGRect titleRect = CGRectMake(titleX, titleY, [self titleSize].width, [self titleSize].height); 49 | NSDictionary *attributes = @{NSFontAttributeName : [self titleFont], NSForegroundColorAttributeName : [self titleColor]}; 50 | [_title drawInRect:titleRect withAttributes:attributes]; 51 | } 52 | 53 | #pragma mark - Custom Accessors 54 | 55 | - (void)setSelected:(BOOL)selected { 56 | _selected = selected; 57 | [self setNeedsDisplay]; 58 | } 59 | 60 | #pragma mark - Public 61 | 62 | - (void)setItemTitle:(NSString *)title { 63 | _title = title; 64 | [self setNeedsDisplay]; 65 | } 66 | 67 | - (void)setItemTitleFont:(CGFloat)fontSize { 68 | _fontSize = fontSize; 69 | [self setNeedsDisplay]; 70 | } 71 | 72 | - (void)setItemSelectedTileFont:(CGFloat)fontSize { 73 | _selectedFontSize = fontSize; 74 | [self setNeedsDisplay]; 75 | } 76 | 77 | - (void)setItemTitleColor:(UIColor *)color { 78 | _color = color; 79 | [self setNeedsDisplay]; 80 | } 81 | 82 | - (void)setItemSelectedTitleColor:(UIColor *)color { 83 | _selectedColor = color; 84 | [self setNeedsDisplay]; 85 | } 86 | 87 | #pragma mark - Private 88 | 89 | - (CGSize)titleSize { 90 | NSDictionary *attributes = @{NSFontAttributeName : [self titleFont]}; 91 | CGSize size = [_title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; 92 | size.width = ceil(size.width); 93 | size.height = ceil(size.height); 94 | 95 | return size; 96 | } 97 | 98 | - (UIFont *)titleFont { 99 | UIFont *font; 100 | if (_selected) { 101 | font = [UIFont boldSystemFontOfSize:_selectedFontSize]; 102 | } else { 103 | font = [UIFont systemFontOfSize:_fontSize]; 104 | } 105 | return font; 106 | } 107 | 108 | - (UIColor *)titleColor { 109 | UIColor *color; 110 | if (_selected) { 111 | color = _selectedColor; 112 | } else { 113 | color = _color; 114 | } 115 | return color; 116 | } 117 | 118 | #pragma mark - Public Class Method 119 | 120 | + (CGFloat)widthForTitle:(NSString *)title { 121 | NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:DEFAULT_TITLE_FONTSIZE]}; 122 | CGSize size = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; 123 | size.width = ceil(size.width) + HORIZONTAL_MARGIN * 2; 124 | 125 | return size.width; 126 | } 127 | 128 | #pragma mark - Responder 129 | 130 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 131 | self.selected = YES; 132 | if (self.delegate && [self.delegate respondsToSelector:@selector(slideBarItemSelected:)]) { 133 | [self.delegate slideBarItemSelected:self]; 134 | } 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideContentView.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideContentView.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/1. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^FDSlideContentViewScrollCallback)(NSUInteger index); 12 | 13 | @protocol FDSlideContentViewDataSource; 14 | //@protocol FDSlideContentViewDelegate; 15 | 16 | @interface FDSlideContentView : UIView 17 | 18 | @property (weak, nonatomic) id dataSource; 19 | //@property (weak, nonatomic) id delegate; 20 | 21 | // Add the calback when the slide content view be scrolled completely 22 | - (void)slideContentViewScrollFinished:(FDSlideContentViewScrollCallback)callback; 23 | 24 | // Set the slide content view to show content at index 25 | - (void)scrollSlideContentViewToIndex:(NSUInteger)index; 26 | 27 | @end 28 | 29 | @protocol FDSlideContentViewDataSource 30 | 31 | // Get the view controller for the index of the content view 32 | - (UIViewController *)slideContentView:(FDSlideContentView *)contentView viewControllerForIndex:(NSUInteger)index; 33 | 34 | // Get the num of content view 35 | - (NSInteger)numOfContentView; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/FDSlideContentView.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideContentView.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/1. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "FDSlideContentView.h" 10 | 11 | @interface FDSlideContentView () 12 | 13 | @property (strong, nonatomic) UIScrollView *scrollView; 14 | @property (strong, nonatomic) FDSlideContentViewScrollCallback callback; 15 | 16 | @property (strong, nonatomic) NSMutableArray *contentsVC; 17 | @property (assign, nonatomic) NSUInteger currentIndex; 18 | 19 | @end 20 | 21 | @implementation FDSlideContentView 22 | 23 | - (void)willMoveToSuperview:(UIView *)newSuperview { 24 | _currentIndex = 0; 25 | [self initScrollView]; 26 | [self initContentView]; 27 | } 28 | 29 | #pragma mark - Custom Accessors 30 | 31 | - (NSMutableArray *)contentsVC { 32 | if (!_contentsVC) { 33 | _contentsVC = [NSMutableArray array]; 34 | NSInteger num; 35 | if (self.dataSource) { 36 | num = [self.dataSource numOfContentView]; 37 | } 38 | 39 | // Get the dataSource 40 | for (int i = 0; i < num; i++) { 41 | UIViewController *vc = [self.dataSource slideContentView:self viewControllerForIndex:i]; 42 | [_contentsVC addObject:vc]; 43 | } 44 | } 45 | return _contentsVC; 46 | } 47 | 48 | #pragma mark - Public 49 | 50 | - (void)slideContentViewScrollFinished:(FDSlideContentViewScrollCallback)callback { 51 | _callback = callback; 52 | } 53 | 54 | - (void)scrollSlideContentViewToIndex:(NSUInteger)index { 55 | self.currentIndex = index; 56 | [self.scrollView scrollRectToVisible:CGRectMake(index * CGRectGetWidth(_scrollView.frame), 0, CGRectGetWidth(_scrollView.frame), CGRectGetHeight(_scrollView.frame)) animated:YES]; 57 | } 58 | 59 | #pragma mark - Private 60 | 61 | - (void)initScrollView { 62 | UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; 63 | scrollView.backgroundColor = [UIColor clearColor]; 64 | scrollView.pagingEnabled = YES; 65 | scrollView.showsHorizontalScrollIndicator = NO; 66 | scrollView.showsVerticalScrollIndicator = NO; 67 | scrollView.bounces = NO; 68 | scrollView.delegate = self; 69 | _scrollView = scrollView; 70 | [self addSubview:_scrollView]; 71 | } 72 | 73 | - (void)initContentView { 74 | for (UIViewController *vc in self.contentsVC) { 75 | NSUInteger index = [self.contentsVC indexOfObject:vc]; 76 | vc.view.frame = CGRectMake(index * CGRectGetWidth(_scrollView.frame), 0, CGRectGetWidth(_scrollView.frame), CGRectGetHeight(_scrollView.frame)); 77 | [_scrollView addSubview:vc.view]; 78 | } 79 | _scrollView.contentSize = CGSizeMake([_contentsVC count] * CGRectGetWidth(_scrollView.frame), CGRectGetHeight(_scrollView.frame)); 80 | } 81 | 82 | #pragma mark - UIScrollViewDelegate 83 | 84 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 85 | CGFloat offsetX = scrollView.contentOffset.x; 86 | NSUInteger index = offsetX / CGRectGetWidth(_scrollView.frame); 87 | self.currentIndex = index; 88 | _callback(index); 89 | } 90 | 91 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 92 | 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.fergus.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIViewControllerBasedStatusBarAppearance 30 | 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AnotherViewController.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/14. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AnotherViewController.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/14. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "FDSlideBar.h" 11 | #import "TableViewCell.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (strong, nonatomic) FDSlideBar *slideBar; 16 | @property (strong, nonatomic) UITableView *tableView; 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | self.view.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:128 / 255.0 alpha:1.0]; 26 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; 27 | 28 | [self setupSlideBar]; 29 | [self setupTableView]; 30 | } 31 | 32 | - (void)didReceiveMemoryWarning { 33 | [super didReceiveMemoryWarning]; 34 | } 35 | 36 | #pragma mark - Private 37 | 38 | // Set up a slideBar and add it into view 39 | - (void)setupSlideBar { 40 | FDSlideBar *sliderBar = [[FDSlideBar alloc] init]; 41 | sliderBar.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:128 / 255.0 alpha:1.0]; 42 | 43 | // Init the titles of all the item 44 | sliderBar.itemsTitle = @[@"要闻", @"视频", @"上海", @"娱乐", @"体育NBA", @"财经", @"科技", @"社会", @"军事", @"时尚", @"汽车", @"游戏", @"图片", @"股票"]; 45 | 46 | // Set some style to the slideBar 47 | sliderBar.itemColor = [UIColor whiteColor]; 48 | sliderBar.itemSelectedColor = [UIColor orangeColor]; 49 | sliderBar.sliderColor = [UIColor orangeColor]; 50 | 51 | // Add the callback with the action that any item be selected 52 | [sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) { 53 | [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; 54 | }]; 55 | [self.view addSubview:sliderBar]; 56 | _slideBar = sliderBar; 57 | } 58 | 59 | // Set up a tableView to show the content 60 | - (void)setupTableView { 61 | // The frame of tableView, be care the width and height property 62 | CGRect frame = CGRectMake(0, 0, CGRectGetMaxY(self.view.frame) - CGRectGetMaxY(self.slideBar.frame), CGRectGetWidth(self.view.frame)); 63 | self.tableView = [[UITableView alloc] initWithFrame:frame]; 64 | [self.view addSubview:self.tableView]; 65 | 66 | // Register the custom cell 67 | UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; 68 | [self.tableView registerNib:nib forCellReuseIdentifier:@"ContentCell"]; 69 | 70 | // Set the tableView center in the bottom of view. so after rotating, it shows rightly 71 | self.tableView.center = CGPointMake(CGRectGetWidth(self.view.frame) * 0.5, CGRectGetHeight(self.view.frame) * 0.5 + CGRectGetMaxY(self.slideBar.frame) * 0.5); 72 | self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 73 | 74 | // Rotate the tableView 90 angle anticlockwise 75 | self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2); 76 | self.tableView.showsVerticalScrollIndicator = NO; 77 | self.tableView.pagingEnabled = YES; 78 | self.tableView.dataSource = self; 79 | self.tableView.delegate = self; 80 | } 81 | 82 | #pragma mark - UITableViewDataSource 83 | 84 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 85 | return [self.slideBar.itemsTitle count]; 86 | } 87 | 88 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 89 | TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ContentCell"]; 90 | 91 | // Rotate the cell's content 90 angle clockwise to show them rightly 92 | cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2); 93 | cell.text = self.slideBar.itemsTitle[indexPath.row]; 94 | return cell; 95 | } 96 | 97 | #pragma mark - UITableViewDelegate 98 | 99 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 100 | // Height retrun the width of screen 101 | return CGRectGetWidth(self.view.frame); 102 | } 103 | 104 | #pragma mark - UIScrollViewDelegate 105 | 106 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 107 | NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:scrollView.contentOffset]; 108 | 109 | // Select the relating item when scroll the tableView by paging. 110 | [self.slideBar selectSlideBarItemAtIndex:indexPath.row]; 111 | } 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/controllers(deprecated)/NewsViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImportantNewsViewController.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/1. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NewsViewController : UIViewController 12 | 13 | @property (copy, nonatomic) NSString *labelText; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/controllers(deprecated)/NewsViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImportantNewsViewController.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/1. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "NewsViewController.h" 10 | 11 | @interface NewsViewController () 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *contentLabel; 14 | 15 | @end 16 | 17 | @implementation NewsViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | self.contentLabel.text = self.labelText; 22 | // Do any additional setup after loading the view from its nib. 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | /* 31 | #pragma mark - Navigation 32 | 33 | // In a storyboard-based application, you will often want to do a little preparation before navigation 34 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 35 | // Get the new view controller using [segue destinationViewController]. 36 | // Pass the selected object to the new view controller. 37 | } 38 | */ 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/controllers(deprecated)/NewsViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/controllers(deprecated)/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/controllers(deprecated)/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "FDSlideBar.h" 11 | #import "FDSlideContentView.h" 12 | #import "NewsViewController.h" 13 | 14 | @interface ViewController () 15 | 16 | @property (strong, nonatomic) FDSlideBar *slideBar; 17 | @property (strong, nonatomic) FDSlideContentView *contentView; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | self.view.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:128 / 255.0 alpha:1.0]; 26 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; 27 | 28 | // Add a slide bar 29 | FDSlideBar *sliderBar = [[FDSlideBar alloc] init]; 30 | sliderBar.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:128 / 255.0 alpha:1.0]; 31 | sliderBar.itemsTitle = @[@"要闻", @"视频", @"上海", @"娱乐", @"体育NBA", @"财经", @"科技", @"社会", @"军事", @"时尚", @"汽车", @"游戏", @"图片", @"股票"]; 32 | sliderBar.itemColor = [UIColor whiteColor]; 33 | sliderBar.itemSelectedColor = [UIColor orangeColor]; 34 | sliderBar.sliderColor = [UIColor orangeColor]; 35 | 36 | [sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) { 37 | // Relate to the content view 38 | [_contentView scrollSlideContentViewToIndex:idx]; 39 | }]; 40 | [self.view addSubview:sliderBar]; 41 | _slideBar = sliderBar; 42 | 43 | // Add a slide content view 44 | FDSlideContentView *contentView = [[FDSlideContentView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(sliderBar.frame), CGRectGetWidth(self.view.frame), CGRectGetMaxY(self.view.frame) - CGRectGetMaxY(sliderBar.frame))]; 45 | [contentView slideContentViewScrollFinished:^(NSUInteger index) { 46 | // Relate to the slide bar 47 | [_slideBar selectSlideBarItemAtIndex:index]; 48 | }]; 49 | contentView.dataSource = self; 50 | contentView.backgroundColor = [UIColor whiteColor]; 51 | [self.view addSubview:contentView]; 52 | _contentView = contentView; 53 | } 54 | 55 | - (void)didReceiveMemoryWarning { 56 | [super didReceiveMemoryWarning]; 57 | // Dispose of any resources that can be recreated. 58 | } 59 | 60 | #pragma mark - FDSlideContentViewDataSource 61 | 62 | - (NSInteger)numOfContentView { 63 | return [self.slideBar.itemsTitle count]; 64 | } 65 | 66 | - (UIViewController *)slideContentView:(FDSlideContentView *)contentView viewControllerForIndex:(NSUInteger)index { 67 | NewsViewController *newsVC = [[NewsViewController alloc] init]; 68 | newsVC.labelText = self.slideBar.itemsTitle[index]; 69 | return newsVC; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemoTests/FDSlideBarDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDSlideBarDemoTests.m 3 | // FDSlideBarDemoTests 4 | // 5 | // Created by fergusding on 15/6/4. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface FDSlideBarDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation FDSlideBarDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /FDSlideBarDemo/FDSlideBarDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.fergus.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /FDSlideBarDemo/TableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.h 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/14. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TableViewCell : UITableViewCell 12 | 13 | @property (strong, nonatomic) NSString *text; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /FDSlideBarDemo/TableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.m 3 | // FDSlideBarDemo 4 | // 5 | // Created by fergusding on 15/7/14. 6 | // Copyright (c) 2015年 fergusding. All rights reserved. 7 | // 8 | 9 | #import "TableViewCell.h" 10 | 11 | @interface TableViewCell () 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *label; 14 | 15 | @end 16 | 17 | @implementation TableViewCell 18 | 19 | - (void)awakeFromNib { 20 | self.selectionStyle = UITableViewCellSelectionStyleNone; 21 | } 22 | 23 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 24 | [super setSelected:selected animated:animated]; 25 | } 26 | 27 | #pragma mark - Custom Accessors 28 | 29 | - (void)setText:(NSString *)text { 30 | _text = text; 31 | self.label.text = text; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /FDSlideBarDemo/TableViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FDSlideBar 2 | A custom slide bar like the top slide menu of NTES news client used in iOS. 3 | 4 | # Introduction 5 | 6 | FDSlideBar is a sliding bar which is muck like the top menu bar of NTES news client. it can scroll the bar and content automaticly with smoth animation. It uses block to receive your deal when you select a itme or scroll the content view to previous or next page. It also support you to set some style such as backgroundColor, font size, text color, selected font size and selected text color and so on. Now I achieve the content by using table view. so it will benefit much from table view, there will be no memory problem and the original animation will surpport better. 7 | 8 | ## Preview 9 | 10 | ![preview](http://7xiamc.com1.z0.glb.clouddn.com/效果.gif) 11 | 12 | ## ScreenShot 13 | 14 | ![one](http://7xiamc.com1.z0.glb.clouddn.com/one.png) 15 | ![two](http://7xiamc.com1.z0.glb.clouddn.com/two.png) 16 | 17 | # Get started 18 | 19 | 1. Download the source file in the folder FDSlideBar. 20 | 2. Add the FDSlideBar.h and FDSlideBar.m files to your project. 21 | 3. Import the FDSlideBar.h file where you want to use it. The new achievement will advise you to use it with table view. 22 | 23 | # Usage 24 | 25 | - There are the key code, others you must read them in the demo for the detail. 26 | 27 | ## FDSlideBar 28 | 29 | ```Objective-C 30 | FDSlideBar *sliderBar = [[FDSlideBar alloc] init]; 31 | sliderBar.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:128 / 255.0 alpha:1.0]; 32 | 33 | // Init the titles of all the item 34 | sliderBar.itemsTitle = @[@"要闻", @"视频", @"上海", @"娱乐", @"体育NBA", @"财经", @"科技", @"社会", @"军事", @"时尚", @"汽车", @"游戏", @"图片", @"股票"]; 35 | 36 | // Set some style to the slideBar 37 | sliderBar.itemColor = [UIColor whiteColor]; 38 | sliderBar.itemSelectedColor = [UIColor orangeColor]; 39 | sliderBar.sliderColor = [UIColor orangeColor]; 40 | 41 | // Add the callback with the action that any item be selected 42 | [sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) { 43 | [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; 44 | }]; 45 | [self.view addSubview:sliderBar]; 46 | _slideBar = sliderBar; 47 | ``` 48 | ## Setup TableView 49 | 50 | ```Objective-C 51 | // The frame of tableView, be care the width and height property 52 | CGRect frame = CGRectMake(0, 0, CGRectGetMaxY(self.view.frame) - CGRectGetMaxY(self.slideBar.frame), CGRectGetWidth(self.view.frame)); 53 | self.tableView = [[UITableView alloc] initWithFrame:frame]; 54 | [self.view addSubview:self.tableView]; 55 | 56 | // Register the custom cell 57 | UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; 58 | [self.tableView registerNib:nib forCellReuseIdentifier:@"ContentCell"]; 59 | 60 | // Set the tableView center in the bottom of view. so after rotating, it shows rightly 61 | self.tableView.center = CGPointMake(CGRectGetWidth(self.view.frame) * 0.5, CGRectGetHeight(self.view.frame) * 0.5 + CGRectGetMaxY(self.slideBar.frame) * 0.5); 62 | self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 63 | 64 | // Rotate the tableView 90 angle anticlockwise 65 | self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2); 66 | self.tableView.showsVerticalScrollIndicator = NO; 67 | self.tableView.pagingEnabled = YES; 68 | self.tableView.dataSource = self; 69 | self.tableView.delegate = self; 70 | ``` 71 | 72 | ## Setup TableView Cell 73 | 74 | ```Objective-C 75 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 76 | TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ContentCell"]; 77 | 78 | // Rotate the cell's content 90 angle clockwise to show them rightly 79 | cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2); 80 | cell.text = self.slideBar.itemsTitle[indexPath.row]; 81 | return cell; 82 | } 83 | ``` 84 | 85 | #License 86 | MIT 87 | -------------------------------------------------------------------------------- /ScreenShot/one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fergusding/FDSlideBar/97e21cffd5d90affeaf341cd7e29cad58474d714/ScreenShot/one.png -------------------------------------------------------------------------------- /ScreenShot/two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fergusding/FDSlideBar/97e21cffd5d90affeaf341cd7e29cad58474d714/ScreenShot/two.png -------------------------------------------------------------------------------- /效果.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fergusding/FDSlideBar/97e21cffd5d90affeaf341cd7e29cad58474d714/效果.gif --------------------------------------------------------------------------------