{"id":19206426,"url":"https://github.com/notfound9/stringcalculate","last_synced_at":"2025-05-12T17:26:40.851Z","repository":{"id":110697397,"uuid":"161145698","full_name":"NotFound9/StringCalculate","owner":"NotFound9","description":"一种更加方便和高效计算多行Label高度的新方法，A new way to calculate label height more convenient  and efficient。","archived":false,"fork":false,"pushed_at":"2019-01-03T08:19:08.000Z","size":49,"stargazers_count":43,"open_issues_count":4,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T15:43:30.021Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NotFound9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-12-10T08:55:34.000Z","updated_at":"2024-09-24T03:02:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"70f29c4f-2621-461c-93b4-7b8f91985a39","html_url":"https://github.com/NotFound9/StringCalculate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotFound9%2FStringCalculate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotFound9%2FStringCalculate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotFound9%2FStringCalculate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotFound9%2FStringCalculate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotFound9","download_url":"https://codeload.github.com/NotFound9/StringCalculate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253786094,"owners_count":21964089,"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":[],"created_at":"2024-11-09T13:15:49.367Z","updated_at":"2025-05-12T17:26:40.844Z","avatar_url":"https://github.com/NotFound9.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StringCalculate\n\n一种更加方便和高效计算多行Label高度的新方法\n\n与系统的提供的boundingRect相比，优点主要有以下两点：\n\n1.耗时较少\n\n在Demo和我们实际项目中测试结果中，时间消耗约为系统的boundingRect方法的30%。\n\n2.调用更加方便。\n\n在使用系统的boundingRect方法进行Label高度计算时，通常情况下，我们需要根据最大行数来估算Label最大的高度，类似于这样：\n```\nlet maxLine = 3//最大行数\nlet singleLineHeight = 20//单行高度\nlet maxHeight = CGFloat(maxLine * singleLineHeight)//计算得到最大宽度\nlet rect = text.boundingRect(with: CGSize(width: UIScreen.main.bounds.size.width, height: maxHeight),\n                                      options: .usesLineFragmentOrigin,\n                                      attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16)],\n                                      context: nil).size.width\n```\n但是在使用这种新方法计算时，我们只需要指定最大高度就行了，类似于这样：\n```\nlet rect = text.boundingRectFast(withMaxWidth: UIScreen.main.bounds.size.width, \n                                          font: UIFont.boldSystemFont(ofSize: 16), \n                                          maxLine: maxLine)\n```\n                   \n介绍文章：https://mp.weixin.qq.com/s/zHAlxALPMFZLv8M8bJaRKA\n\n有问题或者建议欢迎加我微信ruiwendelll，我们一起探讨学习，谢谢了！\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotfound9%2Fstringcalculate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotfound9%2Fstringcalculate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotfound9%2Fstringcalculate/lists"}