├── .gitignore ├── Documentation ├── Logo.png ├── PagerAnimation.gif ├── Pager_Animation_Constant.gif ├── Pager_Animation_None.gif ├── Pager_Animation_Stretched.gif ├── Pager_StripStyle_Dot.png ├── Pager_StripStyle_None.png ├── Pager_StripStyle_Rounded.png ├── Pager_Style_Default.gif ├── Pager_Style_Dot.gif ├── Pager_Style_DotNotAnimated.gif ├── Pager_Style_DotStretched.gif ├── Pager_Style_NotAnimated.gif ├── Pager_Style_Rounded.gif ├── Pager_Style_RoundedNotAnimated.gif ├── Pager_Style_RoundedStretched.gif └── Pager_Style_Stretched.gif ├── LICENSE ├── NuGet └── PagerViewController.nuspec ├── README.md └── Sources ├── PagerViewController.Sample ├── AppDelegate.cs ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Entitlements.plist ├── Info.plist ├── LaunchScreen.storyboard ├── Main.cs ├── PagerViewController.Sample.csproj └── SamplePageViewController.cs ├── PagerViewController.sln └── PagerViewController ├── PagerBar.cs ├── PagerDataSource.cs ├── PagerStyle.cs ├── PagerViewController.cs ├── PagerViewController.csproj └── Properties └── AssemblyInfo.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Documentation/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Logo.png -------------------------------------------------------------------------------- /Documentation/PagerAnimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/PagerAnimation.gif -------------------------------------------------------------------------------- /Documentation/Pager_Animation_Constant.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Animation_Constant.gif -------------------------------------------------------------------------------- /Documentation/Pager_Animation_None.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Animation_None.gif -------------------------------------------------------------------------------- /Documentation/Pager_Animation_Stretched.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Animation_Stretched.gif -------------------------------------------------------------------------------- /Documentation/Pager_StripStyle_Dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_StripStyle_Dot.png -------------------------------------------------------------------------------- /Documentation/Pager_StripStyle_None.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_StripStyle_None.png -------------------------------------------------------------------------------- /Documentation/Pager_StripStyle_Rounded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_StripStyle_Rounded.png -------------------------------------------------------------------------------- /Documentation/Pager_Style_Default.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_Default.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_Dot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_Dot.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_DotNotAnimated.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_DotNotAnimated.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_DotStretched.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_DotStretched.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_NotAnimated.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_NotAnimated.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_Rounded.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_Rounded.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_RoundedNotAnimated.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_RoundedNotAnimated.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_RoundedStretched.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_RoundedStretched.gif -------------------------------------------------------------------------------- /Documentation/Pager_Style_Stretched.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-ad/PagerViewController/20de1442665e54010b71f631f316310c6cf12155/Documentation/Pager_Style_Stretched.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Aloïs Deniel 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 | -------------------------------------------------------------------------------- /NuGet/PagerViewController.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PagerViewController 5 | $version$ 6 | PagerViewController 7 | Aloïs Deniel 8 | Aloïs Deniel 9 | https://github.com/aloisdeniel/PagerViewController/blob/master/LICENSE 10 | https://github.com/aloisdeniel/PagerViewController 11 | https://raw.githubusercontent.com/aloisdeniel/PagerViewController/master/Documentation/Logo.png 12 | false 13 | A basic pager ViewController for Xamarin.iOS, with tabs at the top of the screen. 14 | A basic pager ViewController for Xamarin.iOS, with tabs at the top of the screen. 15 | iOS, Xamarin, tabs, pager, viewpager, slide 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PagerViewController 2 | 3 | A basic pager ViewController for Xamarin.iOS. 4 | 5 | ![Documentation/PagerAnimation.gif](Documentation/PagerAnimation.gif) 6 | 7 | ## Install 8 | 9 | Available on NuGet 10 | 11 | [![NuGet](https://img.shields.io/nuget/v/PagerViewController.svg?label=NuGet)](https://www.nuget.org/packages/PagerViewController/) 12 | 13 | ## Getting started 14 | 15 | ```csharp 16 | var colors = new[] 17 | { 18 | UIColor.FromRGB(76,217,100), 19 | UIColor.FromRGB(52,170,220), 20 | UIColor.FromRGB(88,86,214), 21 | UIColor.FromRGB(255,45,85), 22 | }; 23 | 24 | var pages = new[] 25 | { 26 | new UIViewController() { Title = "First" }, 27 | new UIViewController() { Title = "Second" }, 28 | new UIViewController() { Title = "Third" }, 29 | new UIViewController() { Title = "Last" }, 30 | }; 31 | 32 | var style = new PagerStyle() 33 | { 34 | SelectedStripColors = colors, 35 | }; 36 | 37 | var pager = new PagerViewController(style, pages); 38 | 39 | var nav = new UINavigationController(pager); 40 | nav.NavigationBar.Translucent = false; 41 | ``` 42 | 43 | ## Styling 44 | 45 | ### Predefined styles 46 | 47 | You can pickup one of the predefined styles. 48 | 49 | `PagerStyle.Default` 50 | 51 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_Default.gif) 52 | 53 | `PagerStyle.NotAnimated` 54 | 55 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_NotAnimated.gif) 56 | 57 | `PagerStyle.Stretched` 58 | 59 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_Stretched.gif) 60 | 61 | `PagerStyle.Rounded` 62 | 63 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_Rounded.gif) 64 | 65 | `PagerStyle.RoundedNotAnimated` 66 | 67 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_RoundedNotAnimated.gif) 68 | 69 | `PagerStyle.RoundedStretched` 70 | 71 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_RoundedStretched.gif) 72 | 73 | `PagerStyle.Dot` 74 | 75 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_Dot.gif) 76 | 77 | `PagerStyle.DotAnimated` 78 | 79 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_DotNotAnimated.gif) 80 | 81 | `PagerStyle.DotStretched` 82 | 83 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Style_DotStretched.gif) 84 | 85 | ### Custom 86 | 87 | You can customize appearance of your tabs with the properties of a `PagerStyle` instance. 88 | 89 | #### Strip style 90 | 91 | `StripStyle.None` *(default)* 92 | 93 | ![Documentation/PagerAnimation.gif](Documentation/Pager_StripStyle_None.png) 94 | 95 | `StripStyle.Rounded` 96 | 97 | ![Documentation/PagerAnimation.gif](Documentation/Pager_StripStyle_Rounded.png) 98 | 99 | `StripStyle.Dot` 100 | 101 | ![Documentation/PagerAnimation.gif](Documentation/Pager_StripStyle_Dot.png) 102 | 103 | #### Strip animation 104 | 105 | `StripAnimation.Constant` *(default)* 106 | 107 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Animation_Constant.gif) 108 | 109 | `StripAnimation.Stretched` 110 | 111 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Animation_Stretched.gif) 112 | 113 | `StripAnimation.None` 114 | 115 | ![Documentation/PagerAnimation.gif](Documentation/Pager_Animation_None.gif) 116 | 117 | ## Roadmap / Ideas 118 | 119 | - [X] ViewController 120 | - [X] Animations 121 | - [X] None 122 | - [X] Constant 123 | - [X] Stretched 124 | - [X] Styles 125 | - [X] None 126 | - [X] Rounded 127 | - [X] Dot 128 | - [ ] Setup NuGet 129 | - [ ] More customization 130 | - [ ] Icons 131 | - [ ] Dynamic tabs modification 132 | - [ ] Storyboard integration 133 | 134 | 135 | ## About 136 | 137 | This view controller did the trick but is far from a real polished software and needs some work for real customization. Meanwhile, it can save some time to someone, maybe ... And I'll not lost it! 138 | 139 | ## Contributions 140 | 141 | Contributions are welcome! If you find a bug please report it and if you want a feature please report it. 142 | 143 | If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request. 144 | 145 | ### License 146 | 147 | MIT © [Aloïs Deniel](http://aloisdeniel.github.io) -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | using UIKit; 3 | using Pager; 4 | 5 | namespace Pager.Sample 6 | { 7 | // The UIApplicationDelegate for the application. This class is responsible for launching the 8 | // User Interface of the application, as well as listening (and optionally responding) to application events from iOS. 9 | [Register("AppDelegate")] 10 | public class AppDelegate : UIApplicationDelegate 11 | { 12 | // class-level declarations 13 | 14 | public override UIWindow Window 15 | { 16 | get; 17 | set; 18 | } 19 | 20 | public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 21 | { 22 | var colors = new[] 23 | { 24 | UIColor.FromRGB(76,217,100), 25 | UIColor.FromRGB(52,170,220), 26 | UIColor.FromRGB(88,86,214), 27 | UIColor.FromRGB(255,45,85), 28 | }; 29 | 30 | var pages = new[] 31 | { 32 | new SamplePageViewController(colors[0]) { Title = "First" }, 33 | new SamplePageViewController(colors[1]) { Title = "Second" }, 34 | new SamplePageViewController(colors[2]) { Title = "Third" }, 35 | new SamplePageViewController(colors[3]) { Title = "Last" }, 36 | }; 37 | 38 | var pager = new PagerViewController(new PagerStyle(PagerStyle.DotStretched) { SelectedStripColors = colors }, pages); 39 | 40 | var nav = new UINavigationController(pager); 41 | nav.NavigationBar.Translucent = false; 42 | 43 | this.Window = new UIWindow(UIScreen.MainScreen.Bounds); 44 | this.Window.RootViewController = nav; 45 | this.Window.MakeKeyAndVisible(); 46 | 47 | return true; 48 | } 49 | 50 | public override void OnResignActivation(UIApplication application) 51 | { 52 | // Invoked when the application is about to move from active to inactive state. 53 | // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 54 | // or when the user quits the application and it begins the transition to the background state. 55 | // Games should use this method to pause the game. 56 | } 57 | 58 | public override void DidEnterBackground(UIApplication application) 59 | { 60 | // Use this method to release shared resources, save user data, invalidate timers and store the application state. 61 | // If your application supports background exection this method is called instead of WillTerminate when the user quits. 62 | } 63 | 64 | public override void WillEnterForeground(UIApplication application) 65 | { 66 | // Called as part of the transiton from background to active state. 67 | // Here you can undo many of the changes made on entering the background. 68 | } 69 | 70 | public override void OnActivated(UIApplication application) 71 | { 72 | // Restart any tasks that were paused (or not yet started) while the application was inactive. 73 | // If the application was previously in the background, optionally refresh the user interface. 74 | } 75 | 76 | public override void WillTerminate(UIApplication application) 77 | { 78 | // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground. 79 | } 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "idiom": "iphone", 5 | "size": "29x29", 6 | "scale": "1x" 7 | }, 8 | { 9 | "idiom": "iphone", 10 | "size": "29x29", 11 | "scale": "2x" 12 | }, 13 | { 14 | "idiom": "iphone", 15 | "size": "29x29", 16 | "scale": "3x" 17 | }, 18 | { 19 | "idiom": "iphone", 20 | "size": "40x40", 21 | "scale": "2x" 22 | }, 23 | { 24 | "idiom": "iphone", 25 | "size": "40x40", 26 | "scale": "3x" 27 | }, 28 | { 29 | "idiom": "iphone", 30 | "size": "57x57", 31 | "scale": "1x" 32 | }, 33 | { 34 | "idiom": "iphone", 35 | "size": "57x57", 36 | "scale": "2x" 37 | }, 38 | { 39 | "idiom": "iphone", 40 | "size": "60x60", 41 | "scale": "2x" 42 | }, 43 | { 44 | "idiom": "iphone", 45 | "size": "60x60", 46 | "scale": "3x" 47 | }, 48 | { 49 | "idiom": "ipad", 50 | "size": "29x29", 51 | "scale": "1x" 52 | }, 53 | { 54 | "idiom": "ipad", 55 | "size": "29x29", 56 | "scale": "2x" 57 | }, 58 | { 59 | "idiom": "ipad", 60 | "size": "40x40", 61 | "scale": "1x" 62 | }, 63 | { 64 | "idiom": "ipad", 65 | "size": "40x40", 66 | "scale": "2x" 67 | }, 68 | { 69 | "idiom": "ipad", 70 | "size": "50x50", 71 | "scale": "1x" 72 | }, 73 | { 74 | "idiom": "ipad", 75 | "size": "50x50", 76 | "scale": "2x" 77 | }, 78 | { 79 | "idiom": "ipad", 80 | "size": "72x72", 81 | "scale": "1x" 82 | }, 83 | { 84 | "idiom": "ipad", 85 | "size": "72x72", 86 | "scale": "2x" 87 | }, 88 | { 89 | "idiom": "ipad", 90 | "size": "76x76", 91 | "scale": "1x" 92 | }, 93 | { 94 | "idiom": "ipad", 95 | "size": "76x76", 96 | "scale": "2x" 97 | }, 98 | { 99 | "size": "24x24", 100 | "idiom": "watch", 101 | "scale": "2x", 102 | "role": "notificationCenter", 103 | "subtype": "38mm" 104 | }, 105 | { 106 | "size": "27.5x27.5", 107 | "idiom": "watch", 108 | "scale": "2x", 109 | "role": "notificationCenter", 110 | "subtype": "42mm" 111 | }, 112 | { 113 | "size": "29x29", 114 | "idiom": "watch", 115 | "role": "companionSettings", 116 | "scale": "2x" 117 | }, 118 | { 119 | "size": "29x29", 120 | "idiom": "watch", 121 | "role": "companionSettings", 122 | "scale": "3x" 123 | }, 124 | { 125 | "size": "40x40", 126 | "idiom": "watch", 127 | "scale": "2x", 128 | "role": "appLauncher", 129 | "subtype": "38mm" 130 | }, 131 | { 132 | "size": "44x44", 133 | "idiom": "watch", 134 | "scale": "2x", 135 | "role": "longLook", 136 | "subtype": "42mm" 137 | }, 138 | { 139 | "size": "86x86", 140 | "idiom": "watch", 141 | "scale": "2x", 142 | "role": "quickLook", 143 | "subtype": "38mm" 144 | }, 145 | { 146 | "size": "98x98", 147 | "idiom": "watch", 148 | "scale": "2x", 149 | "role": "quickLook", 150 | "subtype": "42mm" 151 | } 152 | ], 153 | "info": { 154 | "version": 1, 155 | "author": "xcode" 156 | } 157 | } -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | Pager 7 | CFBundleIdentifier 8 | com.aloisdeniel.pager.pager 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 10.1 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UILaunchStoryboardName 23 | LaunchScreen 24 | UIRequiredDeviceCapabilities 25 | 26 | armv7 27 | 28 | UISupportedInterfaceOrientations 29 | 30 | UIInterfaceOrientationPortrait 31 | UIInterfaceOrientationLandscapeLeft 32 | UIInterfaceOrientationLandscapeRight 33 | 34 | XSAppIconAssets 35 | Assets.xcassets/AppIcon.appiconset 36 | 37 | 38 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/LaunchScreen.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 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/Main.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace PagerViewController.Sample 4 | { 5 | public class Application 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, "AppDelegate"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/PagerViewController.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Exe 9 | PagerViewController.Sample 10 | PagerViewController.Sample 11 | Resources 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhoneSimulator\Debug 18 | DEBUG;ENABLE_TEST_CLOUD; 19 | prompt 20 | 4 21 | iPhone Developer 22 | true 23 | true 24 | true 25 | true 26 | true 27 | 30932 28 | None 29 | x86_64 30 | HttpClientHandler 31 | Default 32 | false 33 | 34 | 35 | pdbonly 36 | true 37 | bin\iPhone\Release 38 | 39 | prompt 40 | 4 41 | iPhone Developer 42 | true 43 | true 44 | true 45 | Entitlements.plist 46 | SdkOnly 47 | ARMv7, ARM64 48 | HttpClientHandler 49 | Default 50 | 51 | 52 | pdbonly 53 | true 54 | bin\iPhoneSimulator\Release 55 | 56 | prompt 57 | 4 58 | iPhone Developer 59 | true 60 | true 61 | None 62 | x86_64 63 | HttpClientHandler 64 | Default 65 | 66 | 67 | true 68 | full 69 | false 70 | bin\iPhone\Debug 71 | DEBUG;ENABLE_TEST_CLOUD; 72 | prompt 73 | 4 74 | iPhone Developer 75 | true 76 | true 77 | true 78 | true 79 | true 80 | true 81 | true 82 | Entitlements.plist 83 | SdkOnly 84 | ARMv7, ARM64 85 | HttpClientHandler 86 | Default 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | {7129BABF-BDFF-492B-A19E-73240656573D} 116 | PagerViewController 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Sources/PagerViewController.Sample/SamplePageViewController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UIKit; 3 | 4 | namespace Pager.Sample 5 | { 6 | public class SamplePageViewController : UIViewController 7 | { 8 | public SamplePageViewController(UIColor background) 9 | { 10 | this.background = background; 11 | } 12 | 13 | readonly UIColor background; 14 | 15 | public override void ViewDidLoad() 16 | { 17 | base.ViewDidLoad(); 18 | 19 | this.View = new UILabel(this.View.Frame) 20 | { 21 | Text = this.Title, 22 | TextColor = UIColor.White, 23 | BackgroundColor = background, 24 | TextAlignment = UITextAlignment.Center, 25 | }; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/PagerViewController.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PagerViewController", "PagerViewController\PagerViewController.csproj", "{7129BABF-BDFF-492B-A19E-73240656573D}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PagerViewController.Sample", "PagerViewController.Sample\PagerViewController.Sample.csproj", "{184DDE23-30A9-44F5-B133-AA5C0D12EC3D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 13 | Release|iPhone = Release|iPhone 14 | Release|iPhoneSimulator = Release|iPhoneSimulator 15 | Debug|iPhone = Debug|iPhone 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 23 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 24 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|iPhone.ActiveCfg = Release|Any CPU 25 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|iPhone.Build.0 = Release|Any CPU 26 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 27 | {7129BABF-BDFF-492B-A19E-73240656573D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 28 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|iPhone.ActiveCfg = Debug|Any CPU 29 | {7129BABF-BDFF-492B-A19E-73240656573D}.Debug|iPhone.Build.0 = Debug|Any CPU 30 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator 31 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator 32 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|Any CPU.ActiveCfg = Release|iPhone 33 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|Any CPU.Build.0 = Release|iPhone 34 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 35 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 36 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|iPhone.ActiveCfg = Release|iPhone 37 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|iPhone.Build.0 = Release|iPhone 38 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 39 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 40 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|iPhone.ActiveCfg = Debug|iPhone 41 | {184DDE23-30A9-44F5-B133-AA5C0D12EC3D}.Debug|iPhone.Build.0 = Debug|iPhone 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /Sources/PagerViewController/PagerBar.cs: -------------------------------------------------------------------------------- 1 | namespace Pager 2 | { 3 | using System; 4 | using System.Linq; 5 | using CoreGraphics; 6 | using UIKit; 7 | 8 | /// 9 | /// Represents the tab view. 10 | /// 11 | internal class PagerBar : UIView 12 | { 13 | public PagerBar(PagerStyle style) 14 | { 15 | this.Frame = new CGRect(0, 0, 0, style.SelectedStripSize); 16 | this.style = style; 17 | this.BackgroundColor = style.BarBackgroundColor; 18 | 19 | const int border = 1; 20 | var bottomBorder = new UIView(new CGRect(0, this.Bounds.Height - border, this.Bounds.Width, border)) 21 | { 22 | BackgroundColor = style.BottomBorderColor, 23 | AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin, 24 | }; 25 | this.AddSubview(bottomBorder); 26 | 27 | var frame = this.Bounds; 28 | frame.Y = this.Bounds.Height - style.SelectedStripSize - style.SelectedStripMargin; 29 | frame.Height = style.SelectedStripSize; 30 | 31 | if (style.SelectedStripStyle == PagerStyle.StripStyle.Dot) 32 | { 33 | frame.Width = style.SelectedStripSize; 34 | } 35 | 36 | frame.X = (this.Bounds.Width / 2) - (frame.Width / 2); 37 | 38 | this.selectedView = new UIView(frame) 39 | { 40 | BackgroundColor = GetStripColor(0), 41 | }; 42 | 43 | if (style.SelectedStripStyle == PagerStyle.StripStyle.Rounded || style.SelectedStripStyle == PagerStyle.StripStyle.Dot) 44 | { 45 | this.selectedView.Layer.CornerRadius = style.SelectedStripSize * 0.5f; 46 | } 47 | 48 | if (style.SelectedStripStyle == PagerStyle.StripStyle.Dot) 49 | { 50 | this.selectedView.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin; 51 | } 52 | else 53 | { 54 | this.selectedView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin; 55 | } 56 | 57 | this.AddSubview(this.selectedView); 58 | } 59 | 60 | #region Events 61 | 62 | public class ValueChangedEventArgs 63 | { 64 | public int OldValue { get; set; } 65 | 66 | public int NewValue { get; set; } 67 | } 68 | 69 | public event EventHandler TabSelected; 70 | 71 | #endregion 72 | 73 | #region Fields 74 | 75 | private PagerStyle style; 76 | 77 | private string[] sections = { }; 78 | 79 | private UILabel[] labels = { }; 80 | 81 | private UIView selectedView; 82 | 83 | #endregion 84 | 85 | #region Private properties 86 | 87 | private int SectionCount => Math.Max(1, this.sections.Length); 88 | 89 | private nfloat TabWidth => this.Bounds.Size.Width / this.SectionCount; 90 | 91 | #endregion 92 | 93 | #region Property 94 | 95 | public int SelectedIndex { get; private set; } = 0; 96 | 97 | public string[] Sections 98 | { 99 | get { return sections; } 100 | set 101 | { 102 | if (this.sections != value) 103 | { 104 | this.sections = value; 105 | UpdateLabels(); 106 | UpdateSelectedPosition(false); 107 | } 108 | } 109 | } 110 | 111 | #endregion 112 | 113 | #region Methods 114 | 115 | private void SelectAndRaise(int index, bool animated) 116 | { 117 | var oldValue = this.SelectedIndex; 118 | this.Select(index, animated); 119 | var newValue = this.SelectedIndex; 120 | if (oldValue != newValue) 121 | this.TabSelected?.Invoke(this, new ValueChangedEventArgs() { OldValue = oldValue, NewValue = newValue }); 122 | } 123 | 124 | public void Select(int index, bool animated) 125 | { 126 | var newIndex = Math.Min(SectionCount - 1, Math.Max(0, index)); 127 | if (newIndex != SelectedIndex) 128 | { 129 | this.SelectedIndex = newIndex; 130 | this.UpdateSelectedPosition(animated); 131 | } 132 | } 133 | 134 | #endregion 135 | 136 | #region Updating 137 | 138 | private void UpdateLabels() 139 | { 140 | if (this.labels.Length > 0) 141 | { 142 | foreach (var label in this.labels) 143 | { 144 | label.RemoveFromSuperview(); 145 | } 146 | } 147 | 148 | this.labels = new UILabel[this.sections.Length]; 149 | 150 | var tabSize = new CGSize(TabWidth, this.selectedView.Frame.Y); 151 | 152 | if (style.SelectedStripStyle != PagerStyle.StripStyle.Dot) 153 | { 154 | var stripFrame = this.selectedView.Frame; 155 | stripFrame.Width = tabSize.Width; 156 | this.selectedView.Frame = stripFrame; 157 | } 158 | 159 | for (int i = 0; i < this.sections.Length; i++) 160 | { 161 | var section = this.sections[i]; 162 | var location = new CGPoint(i * tabSize.Width, 0); 163 | var label = new UILabel(new CGRect(location, tabSize)) 164 | { 165 | Text = section, 166 | Font = style.LabelFont, 167 | TextAlignment = UITextAlignment.Center, 168 | TextColor = (this.SelectedIndex == i) ? this.style.SelectedLabelColor : this.style.UnselectedLabelColor, 169 | AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin, 170 | }; 171 | this.labels[i] = label; 172 | this.AddSubview(label); 173 | } 174 | } 175 | 176 | private UIColor GetStripColor(int index) => this.style.SelectedStripColors[index % this.style.SelectedStripColors.Length]; 177 | 178 | private void UpdateLabelColors(int touched = -1) 179 | { 180 | for (int i = 0; i < this.labels.Length; i++) 181 | { 182 | var label = this.labels[i]; 183 | 184 | if (i == touched) 185 | label.TextColor = GetStripColor(i); 186 | else if (i == this.SelectedIndex) 187 | label.TextColor = this.style.SelectedLabelColor; 188 | else 189 | label.TextColor = this.style.UnselectedLabelColor; 190 | } 191 | } 192 | 193 | private void UpdateSelectedPosition(bool animated) 194 | { 195 | // Labels 196 | 197 | this.UpdateLabelColors(); 198 | 199 | // Strip 200 | 201 | var y = this.selectedView.Frame.Y; 202 | var x = TabWidth * SelectedIndex + (TabWidth / 2); 203 | var height = this.selectedView.Frame.Height; 204 | var width = TabWidth; 205 | 206 | if (style.SelectedStripStyle == PagerStyle.StripStyle.Rounded) 207 | { 208 | width -= 2 * this.style.SelectedStripMargin; 209 | } 210 | else if (style.SelectedStripStyle == PagerStyle.StripStyle.Dot) 211 | { 212 | width = this.style.SelectedStripSize; 213 | } 214 | 215 | x -= width / 2; 216 | 217 | var destination = new CGRect(x,y,width,height); 218 | 219 | if (animated && this.style.SelectedStripAnimation != PagerStyle.StripAnimation.None) 220 | { 221 | if (this.style.SelectedStripAnimation == PagerStyle.StripAnimation.Stretched) 222 | { 223 | var step = CGRect.Union(selectedView.Frame, destination); 224 | var stepDuration = this.style.SelectedStripAnimationDuration / 2; 225 | UIView.Animate(stepDuration, 0, UIViewAnimationOptions.CurveEaseIn, () => this.selectedView.Frame = step, () => 226 | { 227 | UIView.Animate(stepDuration, 0, UIViewAnimationOptions.CurveEaseOut, () => this.selectedView.Frame = destination , () => { }); 228 | }); 229 | 230 | UIView.Animate(this.style.SelectedStripAnimationDuration, 0, UIViewAnimationOptions.CurveEaseInOut, () => 231 | { 232 | this.selectedView.BackgroundColor = GetStripColor(SelectedIndex); 233 | }, () => { }); 234 | } 235 | else if (this.style.SelectedStripAnimation == PagerStyle.StripAnimation.Constant) 236 | { 237 | UIView.Animate(this.style.SelectedStripAnimationDuration, 0, UIViewAnimationOptions.CurveEaseInOut, () => 238 | { 239 | this.selectedView.Frame = destination; 240 | this.selectedView.BackgroundColor = GetStripColor(SelectedIndex); 241 | }, () => { }); 242 | 243 | } 244 | } 245 | else 246 | { 247 | this.selectedView.Frame = destination; 248 | this.selectedView.BackgroundColor = GetStripColor(SelectedIndex); 249 | } 250 | } 251 | 252 | #endregion 253 | 254 | #region Touch 255 | 256 | private UILabel GetTouchedLabel(Foundation.NSSet touches) 257 | { 258 | foreach (var item in touches) 259 | { 260 | var touch = (item as UITouch)?.LocationInView(this); 261 | if (touch != null && this.Bounds.Contains(touch.Value)) 262 | { 263 | return this.labels.FirstOrDefault((l) => l.Frame.Contains(touch.Value)); 264 | } 265 | } 266 | 267 | return null; 268 | } 269 | 270 | public override void TouchesCancelled(Foundation.NSSet touches, UIEvent evt) 271 | { 272 | base.TouchesCancelled(touches, evt); 273 | this.UpdateLabelColors(); 274 | } 275 | 276 | public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt) 277 | { 278 | base.TouchesBegan(touches, evt); 279 | this.TouchesMoved(touches, evt); 280 | } 281 | 282 | public override void TouchesMoved(Foundation.NSSet touches, UIEvent evt) 283 | { 284 | base.TouchesMoved(touches, evt); 285 | 286 | var touchedindex = -1; 287 | var touchedlabel = this.GetTouchedLabel(touches); 288 | if (touchedlabel != null) 289 | { 290 | touchedindex = labels.ToList().IndexOf(touchedlabel); 291 | } 292 | 293 | this.UpdateLabelColors(touchedindex); 294 | } 295 | 296 | public override void TouchesEnded(Foundation.NSSet touches, UIEvent evt) 297 | { 298 | base.TouchesEnded(touches, evt); 299 | 300 | this.UpdateLabelColors(); 301 | 302 | var label = this.GetTouchedLabel(touches); 303 | if (label != null) 304 | { 305 | var index = labels.ToList().IndexOf(label); 306 | this.SelectAndRaise(index, true); 307 | } 308 | } 309 | 310 | #endregion 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /Sources/PagerViewController/PagerDataSource.cs: -------------------------------------------------------------------------------- 1 | namespace Pager 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using UIKit; 7 | 8 | internal class PagerDataSource : UIPageViewControllerDataSource 9 | { 10 | private List children; 11 | 12 | public PagerDataSource(UIViewController[] children) 13 | { 14 | this.children = children.ToList(); 15 | } 16 | 17 | override public UIViewController GetPreviousViewController(UIPageViewController pageViewController, UIViewController referenceViewController) 18 | { 19 | var currentIndex = this.children.IndexOf(referenceViewController); 20 | if (currentIndex == 0) 21 | return null; 22 | currentIndex--; 23 | return this.children[currentIndex]; 24 | } 25 | 26 | override public UIViewController GetNextViewController(UIPageViewController pageViewController, UIViewController referenceViewController) 27 | { 28 | var currentIndex = this.children.IndexOf(referenceViewController); 29 | if (currentIndex >= this.children.Count - 1) 30 | return null; 31 | currentIndex++; 32 | return this.children[currentIndex]; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/PagerViewController/PagerStyle.cs: -------------------------------------------------------------------------------- 1 | namespace Pager 2 | { 3 | using System; 4 | using System.Linq; 5 | using UIKit; 6 | 7 | /// 8 | /// Represents the pager style. 9 | /// 10 | public class PagerStyle 11 | { 12 | #region Default styles 13 | 14 | public static PagerStyle Default => new PagerStyle(); 15 | 16 | public static PagerStyle NotAnimated => new PagerStyle() 17 | { 18 | SelectedStripAnimation = PagerStyle.StripAnimation.None, 19 | SelectedStripStyle = PagerStyle.StripStyle.None, 20 | }; 21 | 22 | public static PagerStyle Rounded => new PagerStyle() 23 | { 24 | SelectedStripSize = 5.0f, 25 | SelectedStripMargin = 3.0f, 26 | SelectedStripAnimation = PagerStyle.StripAnimation.Constant, 27 | SelectedStripStyle = PagerStyle.StripStyle.Rounded, 28 | }; 29 | 30 | public static PagerStyle Dot => new PagerStyle() 31 | { 32 | SelectedStripSize = 5.0f, 33 | SelectedStripMargin = 3.0f, 34 | SelectedStripStyle = PagerStyle.StripStyle.Dot, 35 | }; 36 | 37 | public static PagerStyle Stretched => new PagerStyle(Default) 38 | { 39 | SelectedStripAnimation = PagerStyle.StripAnimation.Stretched, 40 | }; 41 | 42 | public static PagerStyle DotNotAnimated => new PagerStyle(Dot) 43 | { 44 | SelectedStripAnimation = PagerStyle.StripAnimation.None, 45 | }; 46 | 47 | public static PagerStyle RoundedNotAnimated => new PagerStyle(Rounded) 48 | { 49 | SelectedStripAnimation = PagerStyle.StripAnimation.None, 50 | }; 51 | 52 | public static PagerStyle DotStretched => new PagerStyle(Dot) 53 | { 54 | SelectedStripAnimation = PagerStyle.StripAnimation.Stretched, 55 | }; 56 | 57 | public static PagerStyle RoundedStretched => new PagerStyle(Rounded) 58 | { 59 | SelectedStripAnimation = PagerStyle.StripAnimation.Stretched, 60 | }; 61 | 62 | #endregion 63 | 64 | public enum StripStyle 65 | { 66 | None, 67 | Rounded, 68 | Dot, 69 | } 70 | 71 | 72 | public enum StripAnimation 73 | { 74 | None, 75 | Constant, 76 | Stretched, 77 | } 78 | 79 | /// 80 | /// Initializes a new instance of the class. 81 | /// 82 | public PagerStyle() { } 83 | 84 | /// 85 | /// Clones the given style. 86 | /// 87 | /// Other. 88 | public PagerStyle(PagerStyle other) 89 | { 90 | this.BarHeight = other.BarHeight; 91 | this.BarBackgroundColor = other.BarBackgroundColor; 92 | this.PagesBackgroundColor = other.PagesBackgroundColor; 93 | this.SelectedStripColors = other.SelectedStripColors.ToArray(); 94 | this.BottomBorderColor = other.BottomBorderColor; 95 | this.LabelFont = other.LabelFont; 96 | this.SelectedStripSize = other.SelectedStripSize; 97 | this.SelectedLabelColor = other.SelectedLabelColor; 98 | this.UnselectedLabelColor = other.UnselectedLabelColor; 99 | this.SelectedStripStyle = other.SelectedStripStyle; 100 | this.SelectedStripMargin = other.SelectedStripMargin; 101 | this.SelectedStripAnimationDuration = other.SelectedStripAnimationDuration; 102 | this.SelectedStripAnimation = other.SelectedStripAnimation; 103 | } 104 | 105 | /// 106 | /// Gets or sets the height of the tab bar. 107 | /// 108 | /// The height of the bar. 109 | public nfloat BarHeight { get; set; } = 35; 110 | 111 | /// 112 | /// Gets or sets the background color of the tab bar. 113 | /// 114 | /// The background color of the tab bar. 115 | public UIColor BarBackgroundColor { get; set; } = UIColor.White; 116 | 117 | /// 118 | /// Gets or sets the color behind the pages. 119 | /// 120 | /// The color behind the pages. 121 | public UIColor PagesBackgroundColor { get; set; } = UIColor.LightGray; 122 | 123 | /// 124 | /// Gets or sets selected strip color for each of the tabs (modulo if smaller than tabs number). 125 | /// 126 | /// The selected strip colors. 127 | public UIColor[] SelectedStripColors { get; set; } = { UIColor.Black }; 128 | 129 | /// 130 | /// Gets or sets the bottom border color. 131 | /// 132 | /// The color of the bottom border. 133 | public UIColor BottomBorderColor { get; set; } = UIColor.FromWhiteAlpha(0.9f,1.0f); 134 | 135 | /// 136 | /// Gets or sets the tab label font. 137 | /// 138 | /// The font. 139 | public UIFont LabelFont { get; set; } = UIFont.SystemFontOfSize(11); 140 | 141 | /// 142 | /// Gets or sets the size of the selected strip. 143 | /// 144 | /// The size of the selected strip. 145 | public float SelectedStripSize { get; set; } = 2.0f; 146 | 147 | /// 148 | /// Gets or sets the selected strip style 149 | /// 150 | /// The size of the selected strip. 151 | public StripStyle SelectedStripStyle { get; set; } = StripStyle.None; 152 | 153 | /// 154 | /// Gets or sets the selected strip animation mode. 155 | /// 156 | /// The animation mode of the selected strip. 157 | public StripAnimation SelectedStripAnimation { get; set; } = StripAnimation.Constant; 158 | 159 | /// 160 | /// Gets or sets the selected strip bottom margin. 161 | /// 162 | /// The size of the selected strip. 163 | public float SelectedStripMargin { get; set; } = 1.0f; 164 | 165 | /// 166 | /// Gets or sets the duration of the strip animation (in seconds). 167 | /// 168 | /// The duration of the selected strip animation. 169 | public float SelectedStripAnimationDuration { get; set; } = 0.20f; 170 | 171 | /// 172 | /// Gets or sets the color of selected labels. 173 | /// 174 | /// The color of the selected label. 175 | public UIColor SelectedLabelColor { get; set; } = UIColor.Black; 176 | 177 | /// 178 | /// Gets or sets the color of unselected labels. 179 | /// 180 | /// The color of the unselected label. 181 | public UIColor UnselectedLabelColor { get; set; } = UIColor.Gray; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /Sources/PagerViewController/PagerViewController.cs: -------------------------------------------------------------------------------- 1 | namespace Pager 2 | { 3 | using System.Linq; 4 | using CoreGraphics; 5 | using UIKit; 6 | 7 | public class PagerViewController : UIViewController 8 | { 9 | #region Constructor 10 | 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The style of the pager. 15 | /// All children view controllers. 16 | public PagerViewController(PagerStyle style, params UIViewController[] children) 17 | { 18 | this.children = children; 19 | this.style = new PagerStyle(style); 20 | } 21 | 22 | #endregion 23 | 24 | #region Fields 25 | 26 | private PagerStyle style; 27 | 28 | private UIPageViewController pager; 29 | 30 | private UIViewController[] children; 31 | 32 | private PagerBar bar; 33 | 34 | #endregion 35 | 36 | #region Lifecycle 37 | 38 | public override void ViewDidLoad() 39 | { 40 | base.ViewDidLoad(); 41 | 42 | this.View.BackgroundColor = this.style.PagesBackgroundColor; 43 | 44 | this.bar = new PagerBar(this.style) 45 | { 46 | Frame = new CGRect(0, 0, this.View.Bounds.Width, this.style.BarHeight), 47 | AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleBottomMargin, 48 | }; 49 | 50 | this.bar.Sections = this.children.Select(vc => vc.Title).ToArray(); 51 | this.bar.TabSelected += OnTabSelected; ; 52 | 53 | this.View.AddSubview(bar); 54 | 55 | // Pager 56 | 57 | this.pager = new UIPageViewController(UIPageViewControllerTransitionStyle.Scroll, UIPageViewControllerNavigationOrientation.Horizontal); 58 | this.pager.DidFinishAnimating += OnPageSwiped; 59 | this.pager.DataSource = new PagerDataSource(children); 60 | this.pager.SetViewControllers(children.Take(1).ToArray(), UIPageViewControllerNavigationDirection.Forward, false, s => { }); 61 | 62 | this.AddChildViewController(pager); 63 | pager.DidMoveToParentViewController(this); 64 | 65 | this.View.AddSubview(this.pager.View); 66 | } 67 | 68 | public override void ViewDidLayoutSubviews() 69 | { 70 | base.ViewDidLayoutSubviews(); 71 | 72 | var pagerView = this.pager.View; 73 | pagerView.Frame = new CGRect(0, this.style.BarHeight, this.View.Bounds.Width, this.View.Bounds.Height - this.style.BarHeight); 74 | pagerView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleBottomMargin; 75 | } 76 | 77 | #endregion 78 | 79 | #region Tab selection 80 | 81 | private void OnPageSwiped(object sender, UIPageViewFinishedAnimationEventArgs e) 82 | { 83 | if (e.Completed) 84 | { 85 | var index = this.children.ToList().IndexOf(this.pager.ViewControllers[0]); 86 | this.bar.Select(index, true); 87 | } 88 | } 89 | 90 | private void OnTabSelected(object sender, PagerBar.ValueChangedEventArgs e) 91 | { 92 | var direction = (e.OldValue < e.NewValue) ? UIPageViewControllerNavigationDirection.Forward : UIPageViewControllerNavigationDirection.Reverse; 93 | this.pager.SetViewControllers(new[] { children[e.NewValue] }, direction, true, s => { }); 94 | } 95 | 96 | #endregion 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Sources/PagerViewController/PagerViewController.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {7129BABF-BDFF-492B-A19E-73240656573D} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Library 9 | PagerViewController 10 | PagerViewController 11 | Resources 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG; 19 | prompt 20 | 4 21 | iPhone Developer 22 | true 23 | true 24 | true 25 | true 26 | true 27 | 42853 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release 33 | prompt 34 | 4 35 | iPhone Developer 36 | true 37 | true 38 | SdkOnly 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Sources/PagerViewController/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("PagerViewController")] 8 | [assembly: AssemblyDescription("Tabs at the top of the screen for Xamarin.iOS.")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("(c) Aloïs Deniel")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | --------------------------------------------------------------------------------