{"id":327,"date":"2015-06-15T15:24:02","date_gmt":"2015-06-15T07:24:02","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=327"},"modified":"2016-07-15T17:37:19","modified_gmt":"2016-07-15T09:37:19","slug":"%e5%85%b3%e4%ba%8e%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%98%be%e7%a4%ba%e9%95%bf%e5%ba%a6sizewithfont%e8%a6%81%e8%af%b4%e5%87%a0%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2015\/06\/15\/152402327.html","title":{"rendered":"\u5173\u4e8e\u5b57\u7b26\u4e32\u663e\u793a\u957f\u5ea6sizeWithFont\u8981\u8bf4\u51e0\u53e5"},"content":{"rendered":"<p>1\u3001\u5728iOS7\u4e4b\u524d\uff0c\u52a8\u6001\u5e03\u5c40\u573a\u666f\u4e2d\uff0c\u7531\u4e8e\u521d\u59cb\u5316UILable\u7684\u5927\u5c0f\u4e0e\u5b9e\u9645\u9700\u8981\u663e\u793a\u7684\u6587\u5b57\u5185\u5bb9\u6709\u65f6\u5019\u4f1a\u51b2\u7a81\uff0c\u7b80\u5355\u4e00\u70b9\u8bb2UILable\u521d\u59cb\u65f6\u8bbe\u5c0f\u4e86\uff0c\u6587\u5b57\u8fc7\u591a\u663e\u793a\u4e0d\u5b8c\uff0c\u6216\u8005\u521d\u59cb\u8bbe\u7f6e\u592a\u5927\u4e86\uff0c\u6587\u5b57\u8f83\u5c11\uff0c\u663e\u793a\u6548\u679c\u8fc7\u4e8e\u7a7a\u8361\u3002<\/p>\n<p>2\u3001\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff0c\u4e00\u822c\u9700\u8981\u7528\u5230NSString\u7684\u4e24\u4e2a\u76f8\u5173\u65b9\u6cd5\uff1a<\/p>\n<p><span style=\"font-family: Arial;\"><span style=\"color: red;\">&#8211; (CGSize)sizeWithFont:(UIFont *)font<\/p>\n<p>&#8211; (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size<\/span><\/span><\/p>\n<p>3\u3001\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u4e0d\u964c\u751f\uff0c\u4f46\u5728iOS7\u4e4b\u540e\u6b64\u7c7b\u65b9\u6cd5\u90fd\u5df2\u8fc7\u671f\uff0c\u5b98\u65b9\u4e0d\u63a8\u8350\u4f7f\u7528\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u5bf9\u5e94\u4e24\u4e2a\u65b9\u6cd5\u4e3a\uff1a<\/p>\n<p><span style=\"font-family: Arial;\"><span style=\"color: red;\">&#8211; (CGSize)sizeWithAttributes:(NSDictionary *)attrs<\/p>\n<p>&#8211; (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context<\/span><\/span><!--more--><\/p>\n<p>4\u3001\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u770b\u8d77\u6765\u5c31\u5f88\u590d\u6742\uff0c\u5f80\u5f80\u6211\u4eec\u4e60\u60ef\u4e86\u4ee5\u524d\u7684\u65b9\u5f0f\uff0c\u5c31\u4e0d\u613f\u610f\u53bb\u6362\uff0c\u7136\u800cxCode\u53c8\u603b\u662f\u62a5\u8b66\u544a\uff0c\u5f88\u591a\u5f3a\u8feb\u75c7\u60a3\u8005\u80af\u5b9a\u53c8\u65e0\u6cd5\u63a5\u53d7\uff0c\u6240\u4ee5\u5927\u5bb6\u90fd\u70e6\uff0c\u6211\u53ea\u80fd\u8bf4\uff0c\u5475\u5475&#8230;.<\/p>\n<p>5\u3001\u597d\u4e86\u4e0d\u591a\u626f\u6de1\uff0c\u63a5\u4e0b\u6765\u5bf9\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u505a\u4e2a\u89e3\u91ca\uff0c\u76f8\u4fe1\u4f60\u5c31\u4e0d\u4f1a\u6297\u62d2\u4e86\uff1a<\/p>\n<p><span style=\"font-family: Arial;\">&#8211; (CGSize)sizeWithAttributes:(NSDictionary *)attrs<\/span><span style=\"font-family: Arial;\"><span style=\"color: #ff0000;\"><br \/>\n<\/span><\/span>\u8fd9\u4e2a\u65b9\u6cd5\u5176\u5b9e\u53ea\u662f\u6bd4\u539f\u65b9\u6cd5\u529f\u80fd\u66f4\u5f3a\u5927\u4e86\uff0c\u539f\u65b9\u6cd5\u53ea\u4f20\u5b57\u53f7\uff0c\u8fd9\u91cc\u53ef\u4ee5\u4f20\u5404\u79cd\u53c2\u6570\u901a\u8fc7\u4e00\u4e2a\u5b57\u5178\u5199\u5165\uff0c\u6211\u4e0d\u8bb2\u590d\u6742\u4e86\uff0c\u53ea\u8bf4\u4e00\u70b9\uff1a\u4f20\u4e2a\u4ec0\u4e48\u53c2\u6570\u53ef\u4ee5\u5b9e\u73b0\u539f\u65b9\u6cd5\u540c\u6837\u7684\u6548\u679c\uff01<\/p>\n<p><span style=\"font-family: Arial;\">@{NSFontAttributeName:[UIFont systemFontOfSize:10]}<\/span>? ?? ? \u76f8\u5f53\u4e8e\u539f\u6765\u7684? ?? ? <span style=\"font-family: Arial;\">[UIFont systemFontOfSize:10]<\/span><br \/>\n<span style=\"font-family: Arial;\">sizeWithFont:[UIFont systemFontOfSize:10] <\/span>??\u7b49\u540c\u4e8e? ?<span style=\"font-family: Arial;\">sizeWithAttribute:@{NSFontAttributeName:[UIFont systemFontOfSize:10]}<\/span><\/p>\n<p><span style=\"font-family: Arial;\">&#8211; (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context<\/span><br \/>\n\u8fd9\u91cc\u540c\u6837\u505a\u4e2a\u8bf4\u660e\uff1a<\/p>\n<p><span style=\"font-family: Arial;\">size<\/span> \u7b49\u540c\u4e8e \u539f\u6765\u7684<span style=\"font-family: Arial;\">size<\/span><br \/>\n<span style=\"font-family: Arial;\">options<\/span>\u662f\u4e2a\u679a\u4e3e\u503c\uff0c\u4e00\u4e2a\u4e2a\u53bb\u8bd5\uff0c\u6362\u884c\u7528 <span style=\"font-family: Arial;\"><strong>NSStringDrawingUsesLineFragmentOrigin<\/strong><\/span><br \/>\n<span style=\"font-family: Arial;\">attributes<\/span>\u540c\u6837\u662f\u5c06\u5b57\u4f53\u6362\u6210\u5b57\u5178\uff0c\u540c\u4e0a\u7c7b\u4f3c\uff1a<span style=\"font-family: Arial;\">@{NSFontAttributeName:[UIFont systemFontOfSize:10]<\/span><br \/>\n<span style=\"font-family: Arial;\">context<\/span>\u76f4\u63a5\u5199<span style=\"font-family: Arial;\">nil<\/span><\/p>\n<p>\u8fd9\u6837\u591f\u7b80\u5355\u4e86\u5427\uff0c\u61d2\u4eba\u4eec\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5728iOS7\u4e4b\u524d\uff0c\u52a8\u6001\u5e03\u5c40\u573a\u666f\u4e2d\uff0c\u7531\u4e8e\u521d\u59cb\u5316UILable\u7684\u5927\u5c0f\u4e0e\u5b9e\u9645\u9700\u8981\u663e\u793a\u7684\u6587\u5b57\u5185\u5bb9\u6709\u65f6\u5019\u4f1a\u51b2\u7a81\uff0c\u7b80\u5355\u4e00\u70b9\u8bb2UILable\u521d\u59cb\u65f6\u8bbe\u5c0f\u4e86\uff0c\u6587\u5b57\u8fc7\u591a\u663e\u793a\u4e0d\u5b8c\uff0c\u6216\u8005\u521d\u59cb\u8bbe\u7f6e\u592a\u5927\u4e86\uff0c\u6587\u5b57\u8f83\u5c11\uff0c\u663e\u793a\u6548\u679c\u8fc7\u4e8e\u7a7a\u8361\u3002 2\u3001\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff0c\u4e00\u822c\u9700\u8981\u7528\u5230NSString\u7684\u4e24\u4e2a\u76f8\u5173\u65b9\u6cd5\uff1a &#8211; (CGSize)sizeWithFont:(UIFont *)font &#8211; (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size 3\u3001\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u4e0d\u964c\u751f\uff0c\u4f46\u5728iOS7\u4e4b\u540e\u6b64\u7c7b\u65b9\u6cd5\u90fd\u5df2\u8fc7\u671f\uff0c\u5b98\u65b9\u4e0d\u63a8\u8350\u4f7f\u7528\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u5bf9\u5e94\u4e24\u4e2a\u65b9\u6cd5\u4e3a\uff1a &#8211; (CGSize)sizeWithAttributes:(NSDictionary *)attrs &#8211; (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context<\/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-327","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\/327","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=327"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}