{"id":200,"date":"2015-03-11T18:30:10","date_gmt":"2015-03-11T18:30:10","guid":{"rendered":"http:\/\/ootips.org\/yonat\/?p=200"},"modified":"2016-04-17T07:03:29","modified_gmt":"2016-04-17T07:03:29","slug":"the-simplest-ios-badge","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/the-simplest-ios-badge\/","title":{"rendered":"The Simplest iOS Badge"},"content":{"rendered":"<p><a href=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2015\/03\/SimplestBadgeLabel.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2015\/03\/SimplestBadgeLabel.png\" alt=\"SimplestBadgeLabel\" width=\"216\" height=\"80\" class=\"alignright size-full wp-image-217\" \/><\/a><br \/>\nIn the past I used a <a href=\"https:\/\/github.com\/yonat\/BadgeLabel\" target=\"_blank\">UILabel subclass<\/a> to show a badge. But since the dawn of flat UI, there&#8217;s no need to subclass.<\/p>\n<p>Here is all the code you need:<\/p>\n<pre class=\"lang:swift decode:true \">\r\nlet label = UILabel()\r\nlabel.clipsToBounds = true\r\nlabel.layer.cornerRadius = label.font.pointSize * 1.2 \/ 2\r\nlabel.backgroundColor = UIColor.grayColor()\r\nlabel.textColor = UIColor.whiteColor()\r\nlabel.text = \" Some Text \"; \/\/ note spaces before and after text\r\n<\/pre>\n<p>All it does is set the cornerRadius of the label&#8217;s underlying CALayer, and add spaces before and after the label text. That&#8217;s it!<\/p>\n<p>For nicely organized badge extension for UILabel and UIButton and UIBarButtonItem, see this GitHub gist:<br \/>\n<a href=\"https:\/\/gist.github.com\/yonat\/75a0f432d791165b1fd6\" target=\"_blank\">Badge.swift<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past I used a UILabel subclass to show a badge. But since the dawn of flat UI, there&#8217;s no need to subclass. Here is all the code you need: let label = UILabel() label.clipsToBounds = true label.layer.cornerRadius = &hellip; <a href=\"https:\/\/ootips.org\/yonat\/the-simplest-ios-badge\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[18,7,6,14,17],"class_list":["post-200","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cocoa","tag-ios","tag-iphone","tag-sample-code","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-3e","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":12,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":239,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/200\/revisions\/239"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}