{"id":28520093,"url":"https://github.com/danie1s/dnspageview-objc","last_synced_at":"2025-08-22T11:04:46.868Z","repository":{"id":56907697,"uuid":"149746934","full_name":"Danie1s/DNSPageView-ObjC","owner":"Danie1s","description":"DNSPageView 的 Objective-C 版本","archived":false,"fork":false,"pushed_at":"2020-08-17T16:23:35.000Z","size":1374,"stargazers_count":31,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-19T12:06:16.094Z","etag":null,"topics":["cocoapods","ios","objective-c","pageview","xcode"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Danie1s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-21T10:13:27.000Z","updated_at":"2025-06-07T01:00:02.000Z","dependencies_parsed_at":"2022-08-20T19:50:27.542Z","dependency_job_id":null,"html_url":"https://github.com/Danie1s/DNSPageView-ObjC","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/Danie1s/DNSPageView-ObjC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danie1s%2FDNSPageView-ObjC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danie1s%2FDNSPageView-ObjC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danie1s%2FDNSPageView-ObjC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danie1s%2FDNSPageView-ObjC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Danie1s","download_url":"https://codeload.github.com/Danie1s/DNSPageView-ObjC/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danie1s%2FDNSPageView-ObjC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271628166,"owners_count":24792821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","ios","objective-c","pageview","xcode"],"created_at":"2025-06-09T06:38:16.419Z","updated_at":"2025-08-22T11:04:46.856Z","avatar_url":"https://github.com/Danie1s.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DNSPageView-ObjC\n\n[![Version](https://img.shields.io/cocoapods/v/DNSPageView-ObjC.svg?style=flat)](http://cocoapods.org/pods/DNSPageView-ObjC)\n[![License](https://img.shields.io/cocoapods/l/DNSPageView-ObjC.svg?style=flat)](http://cocoapods.org/pods/DNSPageView-ObjC)\n[![Platform](https://img.shields.io/cocoapods/p/DNSPageView-ObjC.svg?style=flat)](http://cocoapods.org/pods/DNSPageView-ObjC)\n\nDNSPageView 的 Objective-C 版本，是一个灵活且易于使用的 pageView 框架，titleView 和 contentView 可以布局在任意地方，可以纯代码初始化，也可以使用 xib 或者 storyboard 初始化，并且提供了常见样式属性进行设置。\n\n如果你使用的开发语言是 Swift，请使用 [DNSPageView](https://github.com/Danie1s/DNSPageView)\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Example](#example)\n- [Usage](#usage)\n  - [直接使用 DNSPageView 初始化](#直接使用-dnspageview-初始化) \n  - [使用 xib 或者 storyboard 初始化](#使用-xib-或者-storyboard-初始化)\n  - [使用 DNSPageViewManager 初始化](#使用-dnspageviewmanager-初始化)\n  - [样式](#样式)\n  - [事件回调](#事件回调)\n  - [常见问题](#常见问题)\n- [License](#license)\n\n## Features:\n\n- [x] 使用简单\n- [x] 多种初始化方式\n- [x] 灵活布局\n- [x] 常见的样式\n- [x] 双击 titleView 的回调\n- [x] contentView 滑动监听\n- [x] 适配 iOS 13 Dark Mode\n- [x] 动态改变样式\n\n## Requirements\n\n- iOS 8.0+\n\n- Xcode 9.0+\n\n\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\n\u003e CocoaPods 1.1+ is required to build DNSPageView.\n\nTo integrate DNSPageView into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\n\ntarget '\u003cYour Target Name\u003e' do\n    pod 'DNSPageView-ObjC'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n\n### Manually\n\nIf you prefer not to use any of the aforementioned dependency managers, you can integrate DNSPageView-ObjC into your project manually.\n\n\n\n## Example\n\nTo run the example project, clone the repo, and run `DNSPageView.xcodeproj` .\n\n\u003cimg src=\"https://github.com/Danie1s/DNSPageView-ObjC/blob/master/Images/1.gif\" width=\"30%\" height=\"30%\"\u003e\n\n\u003cimg src=\"https://github.com/Danie1s/DNSPageView-ObjC/blob/master/Images/2.gif\" width=\"30%\" height=\"30%\"\u003e\n\n\u003cimg src=\"https://github.com/Danie1s/DNSPageView-ObjC/blob/master/Images/3.gif\" width=\"30%\" height=\"30%\"\u003e\n\n\u003cimg src=\"https://github.com/Danie1s/DNSPageView-ObjC/blob/master/Images/4.gif\" width=\"30%\" height=\"30%\"\u003e\n\n\n\n\n\n## Usage\n\n### 直接使用 DNSPageView 初始化\n\n```objective-c\n// 创建 DNSPageStyle，设置样式\nDNSPageStyle *style = [[DNSPageStyle alloc] init];\nstyle.titleViewScrollEnabled = YES;\nstyle.titleScaleEnabled = YES;\n\n// 设置标题内容\nNSArray \u003cNSString *\u003e*titles = @[@\"头条\", @\"视频\", @\"娱乐\", @\"要问\", @\"体育\", @\"科技\", @\"汽车\", @\"时尚\", @\"图片\", @\"游戏\", @\"房产\"];\n\n// 创建每一页对应的 controller\nfor (int i = 0; i \u003c titles.count; i++) {\n    ContentViewController *controller = [[ContentViewController alloc] init];\n    [self addChildViewController:controller];\n}\n\nCGFloat y = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.frame.size.height;\nCGSize size = [UIScreen mainScreen].bounds.size;\n\n// 创建对应的 DNSPageView，并设置它的 frame\nDNSPageView *pageView = [[DNSPageView alloc] initWithFrame:CGRectMake(0, y, size.width, size.height - y) style:style titles:titles childViewControllers:self.childViewControllers currentIndex:7];\n[self.view addSubview:pageView];\n```\n\n\n\n### 使用 xib 或者 storyboard 初始化\n\n 在 `xib` 或者 `storyboard` 中拖出 2 个 `UIView`，让它们分别继承 `DNSPageTitleView` 和 `DNSPageContentView`，拖线到代码中\n\n```objective-c\n@property (weak, nonatomic) IBOutlet DNSPageTitleView *titleView;\n\n@property (weak, nonatomic) IBOutlet DNSPageContentView *contentView;\n```\n\n对 DNSPageTitleView 和 DNSPageContentView 进行设置\n\n```objective-c\n// 创建 DNSPageStyle，设置样式\nDNSPageStyle *style = [[DNSPageStyle alloc] init];\nstyle.titleViewBackgroundColor = [UIColor redColor];\nstyle.showCoverView = YES;\n\n// 设置标题内容\nNSArray \u003cNSString *\u003e*titles = @[@\"头条\", @\"视频\", @\"娱乐\", @\"要问\", @\"体育\"];\n\n// 设置默认的起始位置\nNSInteger startIndex = 2;\n\n// 创建每一页对应的 controller\nfor (int i = 0; i \u003c titles.count; i++) {\n    ContentViewController *controller = [[ContentViewController alloc] init];\n    [self addChildViewController:controller];\n}\n\n// 创建 DNSPageViewManager 来设置它们的样式和布局\nDNSPageViewManager *pageViewManager = [[DNSPageViewManager alloc] initWithStyle:style\n                                                     titles:titles\n                                       childViewControllers:self.childViewControllers\n                                               currentIndex:currentIndex\n                                                  titleView:self.titleView\n                                                contentView:self.contentView];\n\n```\n\n\n\n### 使用 DNSPageViewManager 初始化\n\n创建 DNSPageViewManager\n\n```objective-c\n- (DNSPageViewManager *)pageViewManager {\n    if (!_pageViewManager) {\n        // 创建 DNSPageStyle，设置样式\n        DNSPageStyle *style = [[DNSPageStyle alloc] init];\n        style.showBottomLine = YES;\n        style.titleViewScrollEnabled = YES;\n        style.titleViewBackgroundColor = [UIColor clearColor];\n        \n        // 设置标题内容\n        NSArray \u003cNSString *\u003e*titles = @[@\"头条\", @\"视频\", @\"娱乐\", @\"要问\", @\"体育\"];\n        \n        // 创建每一页对应的 controller\n        for (int i = 0; i \u003c titles.count; i++) {\n            ContentViewController *controller = [[ContentViewController alloc] init];\n            [self addChildViewController:controller];\n        }\n        _pageViewManager = [[DNSPageViewManager alloc] initWithStyle:style titles:titles childViewControllers:self.childViewControllers];\n    }\n    return _pageViewManager;\n}\n```\n\n布局 titleView 和 contentView\n\n```objective-c\n// 单独设置 titleView 的 frame\nself.navigationItem.titleView = self.pageViewManager.titleView;\nself.pageViewManager.titleView.frame = CGRectMake(0, 0, 180, 44);\n\n// 单独设置 contentView 的大小和位置，可以使用 autolayout 或者 frame\nDNSPageContentView *contentView = self.pageViewManager.contentView;\n[self.view addSubview:contentView];\n[contentView makeConstraints:^(MASConstraintMaker *make) {\n    make.edges.equalTo(self.view);\n}];\n\n```\n\n\n\n### 样式\n\n`DNSPageStyle` 中提供了常见样式的属性，可以按照不同的需求进行设置，包括可以设置初始显示的页面\n\n\n\n### 事件回调\n\nDNSPageView 提供了常见事件监听的代理，它属于 `DNSPageTitleViewDelegate` 的中的属性\n\n```objective-c\n/**\n DNSPageView 的事件回调，如果有需要，请让对应的 childViewController 遵守这个协议\n */\n@protocol DNSPageEventHandlerDelegate \u003cNSObject\u003e\n@optional\n\n\n/**\n 重复点击 pageTitleView 后调用\n */\n- (void)titleViewDidSelectSameTitle;\n\n\n/**\n pageContentView 的上一页消失的时候，上一页对应的 controller 调用\n */\n- (void)contentViewDidDisappear;\n\n/**\n pageContentView 滚动停止的时候，当前页对应的 controller 调用\n */\n- (void)contentViewDidEndScroll;\n\n@end\n```\n\n\n\n### 常见问题\n\n- `style.isTitleViewScrollEnabled`\n\n  如果标签比较少，建议设置 `style.titleViewScrollEnabled = NO`，`titleView` 会固定，`style.titleMargin` 不起作用，每个标签平分整个 `titleView` 的宽度，下划线的宽度等于标签的宽度。\n\n  如果标签比较多，建议设置 `style.titleViewScrollEnabled = YES`，`titleView` 会滑动，下划线的宽度随着标签文字的宽度变化而变化\n\n- 标签下划线的宽度跟随文字的宽度\n\n  设置 `style.titleViewScrollEnabled = YES`，可以参考 demo 中的第四种样式。\n\n- 由于 `DNSPageView` 是基于 `UIScrollView` 实现，那么就无法避免它的一些特性：\n\n  - 当控制器被 `UINavigationController` 管理，且 `navigationBar.isTranslucent = YES` 的时候，当前控制器的 `view` 是从 `y = 0` 开始布局的，所以为了防止部分内容被 `navigationBar` 遮挡，系统默认会给 `UIScrollView` 添加 offset。如果想取消这个特性：\n    - iOS 11 以前，在控制器中设置 `self.automaticallyAdjustsScrollViewInsets = NO`\n    - iOS 11 以后引入 `SafeArea` 概念，设置 `UIScrollView` 的属性 `contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever`\n    - 其实这个效果还与 `UIViewController` 的其他属性有关系，但因为各种组合的情景过于复杂，所以不在此一一描述\n  - `DNSPageContentView` 用 `UICollectionView` 实现，所以这个特性有机会造成 `UICollectionView` 的高度小于它的 `item` 的高度，造成奇怪的 Bug。\n  - 以上只是可能出现的 Bug 之一，由于 `Demo` 不能覆盖所有的场景，不同的布局需求可能会引起不同的 Bug，开发者需要明确了解自己的布局需求，注意细节，了解 iOS 布局特性，并且作出对应的调整，不能完全参照 `Demo`。\n\n\n## License\n\nDNSPageView-ObjC is available under the MIT license. See the LICENSE file for more info.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanie1s%2Fdnspageview-objc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanie1s%2Fdnspageview-objc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanie1s%2Fdnspageview-objc/lists"}