{"id":15293602,"url":"https://github.com/acumen1005/aclabelcounting","last_synced_at":"2025-04-13T14:07:53.037Z","repository":{"id":53476251,"uuid":"82772511","full_name":"acumen1005/ACLabelCounting","owner":"acumen1005","description":"Adds animated counting to UILabel for swift","archived":false,"fork":false,"pushed_at":"2021-03-29T17:30:34.000Z","size":225,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T14:07:47.091Z","etag":null,"topics":["counting","ios","swift3","uilabel"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/acumen1005.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-02-22T07:09:21.000Z","updated_at":"2022-03-08T09:15:14.000Z","dependencies_parsed_at":"2022-08-18T02:00:43.390Z","dependency_job_id":null,"html_url":"https://github.com/acumen1005/ACLabelCounting","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acumen1005%2FACLabelCounting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acumen1005%2FACLabelCounting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acumen1005%2FACLabelCounting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acumen1005%2FACLabelCounting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acumen1005","download_url":"https://codeload.github.com/acumen1005/ACLabelCounting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724635,"owners_count":21151561,"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":["counting","ios","swift3","uilabel"],"created_at":"2024-09-30T16:50:10.442Z","updated_at":"2025-04-13T14:07:53.012Z","avatar_url":"https://github.com/acumen1005.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ACLabelCounting\n\n[中文版](./readME_CN.md)\n\nAdds animated counting to UILabel for swift\n\n![](ACLabelCounting.gif)\n\n## Installation\n\nTo integrate ACLabelCounting into your Xcode project using CocoaPods, specify it in your Podfile:\n\n```swift\n\npod 'ACLabelCounting'\n```\n\n## Usage\n\nYou can initialize an ACLabelCounting, and call mehtod `count` , then you get an animated counting label\n\nLinear animation of counts from 0 to 100, data type is integer\n\n```swift\nlabel.count(to: 100)\n```\n\nCount animation from 10 to 100. Duration is 5 seconds. Animation type is fade-in effect. Data type is Double.\n\n```swift\nlabel.count(from: 10,\n            to: 100,\n            duration: 5,\n            animationType: .EaseIn,\n            dataType: .Double)\n```\n\nCounting animation from 0 to 100, duration is 5 seconds, animation type is fade-out effect, data type is Int type. String formatting adds a `%` to the end of the string.\n\n```swift\nlabel.count(from: 0,\n            to: 100,\n            duration: 5,\n            animationType: .EaseOut,\n            dataType: .Int) { txt in\n                return \"\\(txt) %\"\n        }\n```\n\nCount animation from 0 to 100. Duration is 5 seconds. Animation type is fade-in effect. Data type is Int. String formatting is to add `/ 100` to the string face, and its color is bright gray.\n\n```swift\nlabel.count(from: 0,\n                    to: 100,\n                    duration: 5,\n                    animationType: .EaseIn,\n                    dataType: .Int) { text -\u003e NSAttributedString in\n                        let appandString = \" / 100\"\n                        let string = \"\\(text)\\(appandString)\"\n                        let range = (string as NSString).range(of: appandString)\n\n                        let attributedString = NSMutableAttributedString(string: string)\n                        attributedString.addAttribute(NSForegroundColorAttributeName,\n                                                      value: UIColor.lightGray,\n                                                      range: range)\n                        return attributedString;\n        }\n```\n\nThat's all. If you want to add more powerful features, please post an issue for me.\n\n## Source Analytics\n\nthe enum of datatype\n\n```swift\nenum ACLabelCountingDataType {\n    case Int\n    case Double\n}\n```\n\nthe types of counting animation : no effect (same as linear), linear, fade-in, fade-out, fade-in. \n\n```swift\nenum ACLabelCountingAnimationType {\n    case None\n    case Liner\n    case EaseIn\n    case EaseOut\n    case EaseInOut\n}\n```\n\nTheir corresponding functions:\n\n```swift\nextension ACLabelCounting {\n    func liner(progress: Double, totle: Double) -\u003e Double {\n        return progress / totle\n    }\n\n    func easeIn(progress: Double, totle: Double) -\u003e Double {\n        return pow(progress / totle, 3)\n    }\n\n    func easeOut(progress: Double, totle: Double) -\u003e Double {\n        let t = progress / totle\n        return  1 - pow(1 - t, 3)\n    }\n\n    func easeInOut(progress: Double, totle: Double) -\u003e Double {\n        let t = progress / totle\n        return t \u003c 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1\n    }\n}\n```\n\nACLabelCountting has 5 operations：\n\n- start()\n- pause()\n- restore()\n- stop()\n- reset()\n\nThe key is to use the `CADisplayLink` timer to execute the `updateNumber` task at a rate of 35 times per second and add it to the Runloop in .commonModes mode.\n\n```swift\nprivate func fireDisplayLink() {\n        lastUpdate = CACurrentMediaTime()\n        displayLink = CADisplayLink(target: self, selector: #selector(updateNumber))\n        displayLink.preferredFramesPerSecond = LabelCountingConst.countRate\n        displayLink.add(to: RunLoop.main, forMode: .commonModes)\n    }\n```\n\nIt has two simple custom closures: `formatTextClosure` and `attributedTextClosure`. You can implement string processing yourself. It will all appear on your screen.\n\n```swift\nprivate var formatTextClosure: ((String) -\u003e String) = { text -\u003e String in return text }\n\nprivate var attributedTextClosure: ((String) -\u003e NSAttributedString)?\n```\n\n## Thanks\n\nhttps://github.com/dataxpress/UICountingLabel  \nit is a repo for swift. Thanks ~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facumen1005%2Faclabelcounting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facumen1005%2Faclabelcounting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facumen1005%2Faclabelcounting/lists"}