{"id":557,"date":"2014-08-18T19:41:51","date_gmt":"2014-08-18T11:41:51","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=557"},"modified":"2016-07-15T17:25:45","modified_gmt":"2016-07-15T09:25:45","slug":"uiattributedstring%e8%87%aa%e5%8a%a8%e6%8d%a2%e8%a1%8c%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/08\/18\/194151557.html","title":{"rendered":"UIAttributedString\u81ea\u52a8\u6362\u884c\u95ee\u9898"},"content":{"rendered":"<p>\u7f51\u4e0a\u641c\u4e86\u5927\u534a\u5929\uff0c\u5982\u51fa\u4e00\u8f99\u7684\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p>\u8bbe\u7f6e\u884c\u95f4\u8ddd\u548c\u6362\u884c\u6a21\u5f0f\u90fd\u662f\u8bbe\u7f6e\u4e00\u4e2a\u5c5e\u6027\uff1akCTParagraphStyleAttributeName\uff0c\u8fd9\u4e2a\u5c5e\u6027\u91cc\u9762\u53c8\u5206\u4e3a\u5f88\u591a\u5b50<\/p>\n<p>\u5c5e\u6027\uff0c\u5176\u4e2d\u5c31\u5305\u62ec<\/p>\n<p>kCTLineBreakByCharWrapping<br \/>\nkCTParagraphStyleSpecifierLineSpacingAdjustment<\/p>\n<p>\u8bbe\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre lang=\"objc\" line=\"1\">\/\/\u6bb5\u843d\n    \/\/line break\nCTParagraphStyleSetting lineBreakMode;\nCTLineBreakMode lineBreak = kCTLineBreakByCharWrapping; \/\/\u6362\u884c\u6a21\u5f0f\nlineBreakMode.spec = kCTParagraphStyleSpecifierLineBreakMode;\nlineBreakMode.value = &lineBreak;\nlineBreakMode.valueSize = sizeof(CTLineBreakMode);\n\n    \/\/\u884c\u95f4\u8ddd\nCTParagraphStyleSetting LineSpacing;\nCGFloat spacing = 4.0;  \/\/\u6307\u5b9a\u95f4\u8ddd\nLineSpacing.spec = kCTParagraphStyleSpecifierLineSpacingAdjustment;\nLineSpacing.value = &spacing;\nLineSpacing.valueSize = sizeof(CGFloat);\n\nCTParagraphStyleSetting settings[] = {lineBreakMode,LineSpacing};\nCTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, 2);   \/\/\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3asettings\u7684\u957f\u5ea6\n[attributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName\n                         value:(id)paragraphStyle\n                         range:NSMakeRange(0, attributedString.length)];<\/pre>\n<p><!--more--><br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\u7325\u7410\u7684\u5206\u754c\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<pre lang=\"objc\" line=\"1\">\u8fd9\u5e76\u4e0d\u662f\u552f\u4e00\u7684\u65b9\u6cd5\uff0c\u8fd8\u6709\u53e6\u4e00\u79cd\u66ff\u4ee3\u65b9\u6848\uff1a\nCATextLayer *textLayer = [CATextLayer layer];\ntextLayer.string = getAttributedString();\ntextLayer.frame = CGRectMake(0, CGRectGetMaxY(view.frame), 200, 200);\n[self.view.layer addSublayer:textLayer];\nCATextLayer\u53ef\u4ee5\u76f4\u63a5\u652f\u6301NSAttributedString\uff01<\/pre>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\u7325\u7410\u7684\u5206\u754c\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>\u5176\u5b9e\u4e0d\u7528\u8fd9\u4e48\u9ebb\u70e6\uff0c\u4e00\u884c\u4ee3\u7801\u641e\u5b9a\uff01\u54ea\u6015\u662fButton\u4e0a\u7684AttribledText\uff0c\u770b\u597d\u4e86\u522b\u7728\u773c\uff1a<br \/>\nbutton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u4e0a\u641c\u4e86\u5927\u534a\u5929\uff0c\u5982\u51fa\u4e00\u8f99\u7684\u7ed3\u679c\u5982\u4e0b\uff1a \u8bbe\u7f6e\u884c\u95f4\u8ddd\u548c\u6362\u884c\u6a21\u5f0f\u90fd\u662f\u8bbe\u7f6e\u4e00\u4e2a\u5c5e\u6027\uff1akCTParagraphStyleAttributeName\uff0c\u8fd9\u4e2a\u5c5e\u6027\u91cc\u9762\u53c8\u5206\u4e3a\u5f88\u591a\u5b50 \u5c5e\u6027\uff0c\u5176\u4e2d\u5c31\u5305\u62ec kCTLineBreakByCharWrapping kCTParagraphStyleSpecifierLineSpacingAdjustment \u8bbe\u7f6e\u5982\u4e0b\uff1a \/\/\u6bb5\u843d \/\/line break CTParagraphStyleSetting lineBreakMode; CTLineBreakMode lineBreak = kCTLineBreakByCharWrapping; \/\/\u6362\u884c\u6a21\u5f0f lineBreakMode.spec = kCTParagraphStyleSpecifierLineBreakMode; lineBreakMode.value = &#038;lineBreak; lineBreakMode.valueSize = sizeof(CTLineBreakMode); \/\/\u884c\u95f4\u8ddd CTParagraphStyleSetting LineSpacing; CGFloat spacing = 4.0; \/\/\u6307\u5b9a\u95f4\u8ddd LineSpacing.spec = kCTParagraphStyleSpecifierLineSpacingAdjustment; LineSpacing.value = &spacing; LineSpacing.valueSize = sizeof(CGFloat); CTParagraphStyleSetting settings[] = {lineBreakMode,LineSpacing}; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, 2); \/\/\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3asettings\u7684\u957f\u5ea6 [attributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[20],"class_list":["post-557","post","type-post","status-publish","format-standard","hentry","category-project","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=557"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}