{"id":440,"date":"2024-03-01T12:37:03","date_gmt":"2024-03-01T12:37:03","guid":{"rendered":"https:\/\/ootips.org\/yonat\/?p=440"},"modified":"2024-03-01T12:37:28","modified_gmt":"2024-03-01T12:37:28","slug":"the-simplest-checkbox-uibutton","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/the-simplest-checkbox-uibutton\/","title":{"rendered":"The Simplest Checkbox UIButton"},"content":{"rendered":"\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2024\/03\/SimplestCheckbox.png\" alt=\"\" class=\"wp-image-445\" width=\"380\" height=\"74\" style=\"float:right\"\/><\/figure>\n\n\n\n<p>You don&#8217;t need to change the image on tap!<\/p>\n\n\n\n<p>Buttons can change their own images when their state changes, so you only need to change the button state:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: swift; title: ; notranslate\" title=\"\">\nbutton.setImage(UIImage(systemName: &quot;square&quot;), for: .normal)\nbutton.setImage(UIImage(systemName: &quot;checkmark.square.fill&quot;), for: .selected)\nbutton.addAction(UIAction { _ in button.isSelected.toggle() }, for: .touchUpInside)\n<\/pre><\/div>\n\n\n<p>You can also <code>setTitle()<\/code> and it will all work out-of the box, though you may want to adjust the button.configuration to make it look nice.<\/p>\n\n\n\n<p>For a full (yet short) implementation, see my gist:<br><a href=\"https:\/\/gist.github.com\/yonat\/167a375988da6b538cc9a36a1c92a328\" target=\"_blank\" rel=\"noopener\">CheckboxButton.swift<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You don&#8217;t need to change the image on tap! Buttons can change their own images when their state changes, so you only need to change the button state: You can also setTitle() and it will all work out-of the box, &hellip; <a href=\"https:\/\/ootips.org\/yonat\/the-simplest-checkbox-uibutton\/\">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":[7,14,17],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ios","tag-sample-code","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-76","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/440","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=440"}],"version-history":[{"count":11,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/440\/revisions\/452"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}