{"id":596,"date":"2014-07-14T09:36:49","date_gmt":"2014-07-14T01:36:49","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=596"},"modified":"2016-07-15T16:01:55","modified_gmt":"2016-07-15T08:01:55","slug":"%e5%af%8c%e6%96%87%e6%9c%acnsmutableattributedstring%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/07\/14\/093649596.html","title":{"rendered":"\u5bcc\u6587\u672c(NSMutableAttributedString)\u7684\u4f7f\u7528"},"content":{"rendered":"<p><strong>1\u3001\u521b\u5efa\u5bf9\u8c61<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\u3000\u3000NSString *original = @\"\u4eca\u5929\u4f60\u8fd8\u597d\u5417\uff1f\";\n\n\u3000\u3000NSMutableAttributedString *attrTitle = [[NSMutableAttributedStringalloc] initWithString:original];<\/pre>\n<p><strong>2\u3001\u8bbe\u7f6e\u5c5e\u6027<\/strong>(NSForegroundColorAttributeName\u4ee3\u8868\u8981\u8bbe\u7f6e\u989c\u8272\uff0c value\u4ee3\u8868\u503c\uff0c range \u4ee3\u8868\u8303\u56f4)<\/p>\n<pre lang=\"objc\" line=\"1\">\n\u3000\u3000[attrTitle addAttribute:NSForegroundColorAttributeName value:[UIColorblueColor] range:NSMakeRange(0, 2)];\n\/**\n\u3000\u3000\u5176\u4ed6\u8bbe\u7f6e\uff1a\n\n\u3000\u3000\u3000\u30001.NSForegroundColorAttributeName \/\/\u989c\u8272\n\n\u3000\u3000\u3000\u30002.NSFontAttributeName \/\/\u5b57\u4f53\n\n\u3000\u3000\u3000\u30003.NSBackgroundColorAttributeName \/\/\u80cc\u666f\u8272\n\n\u3000\u3000\u3000\/\/\u8fd8\u6709\u5176\u4ed6\u7684\u5f88\u591a\u7684\u5c5e\u6027\uff0c\u53ef\u4ee5\u81ea\u5df1\u53bb\u770b\u82f9\u679c\u7684API\uff0c\u8fd9\u91cc\u4e0d\u518d\u8be6\u8ff0\n*\/<\/pre>\n<p><strong>3\u3001\u6dfb\u52a0\u5230Label\u4e2d<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\n    UILabel *label = [[UILabel alloc] init];\n\n    label.frame = CGRectMake(100, 100, 100, 40);\n\n    [label setAttributedText:attrTitle];\n\n    [self.view addSubview:label];<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u521b\u5efa\u5bf9\u8c61 \u3000\u3000NSString *original = @&#8221;\u4eca\u5929\u4f60\u8fd8\u597d\u5417\uff1f&#8221;; \u3000\u3000NSMutableAttributedString *attrTitle = [[NSMutableAttributedStringalloc] initWithString:original]; 2\u3001\u8bbe\u7f6e\u5c5e\u6027(NSForegroundColorAttributeName\u4ee3\u8868\u8981\u8bbe\u7f6e\u989c\u8272\uff0c value\u4ee3\u8868\u503c\uff0c range \u4ee3\u8868\u8303\u56f4) \u3000\u3000[attrTitle addAttribute:NSForegroundColorAttributeName value:[UIColorblueColor] range:NSMakeRange(0, 2)]; \/** \u3000\u3000\u5176\u4ed6\u8bbe\u7f6e\uff1a \u3000\u3000\u3000\u30001.NSForegroundColorAttributeName \/\/\u989c\u8272 \u3000\u3000\u3000\u30002.NSFontAttributeName \/\/\u5b57\u4f53 \u3000\u3000\u3000\u30003.NSBackgroundColorAttributeName \/\/\u80cc\u666f\u8272 \u3000\u3000\u3000\/\/\u8fd8\u6709\u5176\u4ed6\u7684\u5f88\u591a\u7684\u5c5e\u6027\uff0c\u53ef\u4ee5\u81ea\u5df1\u53bb\u770b\u82f9\u679c\u7684API\uff0c\u8fd9\u91cc\u4e0d\u518d\u8be6\u8ff0 *\/ 3\u3001\u6dfb\u52a0\u5230Label\u4e2d UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(100, 100, 100, 40); [label setAttributedText:attrTitle]; [self.view addSubview:label];<\/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-596","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\/596","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=596"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/596\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}