{"id":17736,"date":"2017-04-14T15:07:37","date_gmt":"2017-04-14T19:07:37","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=17736"},"modified":"2017-04-14T15:07:37","modified_gmt":"2017-04-14T19:07:37","slug":"using-named-ios-font-styles-with-custom-fonts","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/04\/14\/using-named-ios-font-styles-with-custom-fonts\/","title":{"rendered":"Using Named iOS Font Styles With Custom Fonts"},"content":{"rendered":"<p><a href=\"http:\/\/curtclifton.net\/fonts-with-style\">Curt Clifton<\/a>:<\/p>\n<blockquote cite=\"http:\/\/curtclifton.net\/fonts-with-style\"><p>Trying to change the family on the font descriptor gets us a descriptor that includes both the new family and the old named font style [&#8230;] Creating a font from the confused descriptor takes us right back where we started [&#8230;] Our <code>Helvetica<\/code> is nowhere to be found.<\/p><p>[&#8230;]<\/p><p>What if we had a way to maintain the style information even when switching to a custom font? With that available, we could look up the correct font size even when the user changes their preferred content size.<\/p><p>Here&rsquo;s an extension on <code>UIFont<\/code> that does just that. The key trick is using associated objects to piggyback style information on the font.<\/p><p>[&#8230;]<\/p><p>In <code>awakeFromNib<\/code> the fonts will start as those set in the nib or storyboard but will end as our custom fonts. In <code>traitCollectionDidChange<\/code> the fonts will start as our custom ones and will end as our custom ones <em>at the new preferred content size<\/em>.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Curt Clifton: Trying to change the family on the font descriptor gets us a descriptor that includes both the new family and the old named font style [&#8230;] Creating a font from the confused descriptor takes us right back where we started [&#8230;] Our Helvetica is nowhere to be found.[&#8230;]What if we had a way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,133,31,1380,71,901,134],"class_list":["post-17736","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-font","tag-ios","tag-ios-10","tag-programming","tag-swift-programming-language","tag-typography"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=17736"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17736\/revisions"}],"predecessor-version":[{"id":17737,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17736\/revisions\/17737"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}