{"id":18132037,"url":"https://github.com/cemolcay/sizeclasser","last_synced_at":"2025-04-15T23:08:42.062Z","repository":{"id":62455551,"uuid":"89061078","full_name":"cemolcay/SizeClasser","owner":"cemolcay","description":"Device specific UITraitCollection helper with split view detection for iOS.","archived":false,"fork":false,"pushed_at":"2019-11-28T21:14:16.000Z","size":2247,"stargazers_count":35,"open_issues_count":1,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T00:06:02.597Z","etag":null,"topics":["size-classes","split-over","split-view","uitraitcollection"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/cemolcay.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":"2017-04-22T10:12:05.000Z","updated_at":"2023-02-26T21:35:28.000Z","dependencies_parsed_at":"2022-11-01T22:46:43.452Z","dependency_job_id":null,"html_url":"https://github.com/cemolcay/SizeClasser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FSizeClasser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FSizeClasser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FSizeClasser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FSizeClasser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cemolcay","download_url":"https://codeload.github.com/cemolcay/SizeClasser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246126968,"owners_count":20727647,"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","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":["size-classes","split-over","split-view","uitraitcollection"],"created_at":"2024-11-01T12:10:05.879Z","updated_at":"2025-03-30T18:31:44.575Z","avatar_url":"https://github.com/cemolcay.png","language":"Ruby","readme":"SizeClasser\n===\n\nDevice specific `UITraitCollection` helper with split view detection for iOS.\n\nDemo\n----\n\n![alt tag](https://github.com/cemolcay/SizeClasser/blob/master/demo.gif?raw=true)\n\nRequirements\n----\n\n- Swift 3.0+\n- iOS 8.0+\n\nInstall\n----\n\n```\nuse_frameworks!\npod 'SizeClasser'\n```\n\nUsage\n----\n\n[`SizeClasser`](https://github.com/cemolcay/SizeClasser/blob/master/SizeClasser/SizeClasser.swift) is an `OptionSet` type struct.  \nYou can initilize it with your viewController's `traitCollection` property to identify your current device specific orientation and split view status.\n\n``` swift\nlet sizeClasser = SizeClasser(traitCollection: traitCollection)\n```\n\nOptions:\n\n``` swift\n/// Screen height is bigger than width. Portrait mode in all devices.\npublic static let portrait = SizeClasser(rawValue: 1 \u003c\u003c 0)\n/// Screen width is bigger than height. Landscape mode in all devices.\npublic static let landscape = SizeClasser(rawValue: 1 \u003c\u003c 1)\n/// Portrait mode for iPhone devices.\npublic static let iPhonePortrait = SizeClasser(rawValue: 1 \u003c\u003c 2)\n/// Landscape mode for iPhone devices.\npublic static let iPhoneLandscape = SizeClasser(rawValue: 1 \u003c\u003c 3)\n/// Portrait mode for iPad devices.\npublic static let iPadPortrait = SizeClasser(rawValue: 1 \u003c\u003c 4)\n/// Landscape mode for iPad devices.\npublic static let iPadLandscape = SizeClasser(rawValue: 1 \u003c\u003c 5)\n/// Split mode 1/3 of visible area in iPad devices.\npublic static let iPadSplitOneThird = SizeClasser(rawValue: 1 \u003c\u003c 8)\n/// Split mode 1/2 of visible area in iPad devices.\npublic static let iPadSplitHalf = SizeClasser(rawValue: 1 \u003c\u003c 9)\n/// Split mode 2/3 of visible area in iPad devices.\npublic static let iPadSplitTwoThird = SizeClasser(rawValue: 1 \u003c\u003c 10)\n```\n  \nFor example, if you want to detect iPad split view 1/3 on landscape orientation, simply:\n\n``` swift\nguard let trait = SizeClasser(traitCollection: traitCollection) else { return }\nif trait.contains([.iPadLandscape, .iPadSplitOneThird]) {\n  // You are on iPad, landscape and 1/3 split view mode\n  if SizeClasser.isiPadPro {\n    // You are on 12.9\" iPad\n  } else {\n    // You are on regular iPad / iPad mini\n  }\n}\n```\n\nAlso you can use `SizeClasser.isiPadPro` to detect 12.9\" iPad Pro if you want to layout your views more specificly.  \n\n#### Note on `traitCollectionDidChange:previousTraitCollection` function:\nThis function only get called if `traitCollection` changes.  \nIf you are on iPad, either portrait or landscape mode, it won't change 1/3 split view to 2/3 split view transitions.  \niOS calculates them both `compact width regular height` mode.  \nSo, I recommend to use `viewDidLayoutSubviews:` function to detect split view changes specificly.  \n![alt tag](https://github.com/cemolcay/SizeClasser/blob/master/split.png?raw=true)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcemolcay%2Fsizeclasser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcemolcay%2Fsizeclasser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcemolcay%2Fsizeclasser/lists"}