{"action":"opened","issue":{"url":"https://api.github.com/repos/ibireme/YYText/issues/108","labels_url":"https://api.github.com/repos/ibireme/YYText/issues/108/labels{/name}","comments_url":"https://api.github.com/repos/ibireme/YYText/issues/108/comments","events_url":"https://api.github.com/repos/ibireme/YYText/issues/108/events","html_url":"https://github.com/ibireme/YYText/issues/108","id":125134827,"number":108,"title":"YYLabel font size to fit label size","user":{"login":"100mango","id":5073511,"avatar_url":"https://avatars.githubusercontent.com/u/5073511?v=3","gravatar_id":"","url":"https://api.github.com/users/100mango","html_url":"https://github.com/100mango","followers_url":"https://api.github.com/users/100mango/followers","following_url":"https://api.github.com/users/100mango/following{/other_user}","gists_url":"https://api.github.com/users/100mango/gists{/gist_id}","starred_url":"https://api.github.com/users/100mango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/100mango/subscriptions","organizations_url":"https://api.github.com/users/100mango/orgs","repos_url":"https://api.github.com/users/100mango/repos","events_url":"https://api.github.com/users/100mango/events{/privacy}","received_events_url":"https://api.github.com/users/100mango/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-06T08:39:00Z","updated_at":"2016-01-06T08:39:00Z","closed_at":null,"body":"UILabel 有这样的属性`adjustsFontSizeToFitWidth`来调整行数为一行的Label的font size.\r\n但是UILabel和YYLabel好像都没有一个方法来自动放缩字体大小来适应固定的label size。\r\n想要请教一下,YYText框架有无实现这样的方法。我过了一遍YYLabel的头文件，发现`adjustsFontSizeToFitWidth`也没有。\r\n\r\n目前我自己用了别人之前用在UILabel的思路来实现：\r\n\r\n~~~objective-c\r\n- (void) sizeLabel: (YYLabel *) label toRect: (CGRect) labelRect  {\r\n    \r\n    // Set the frame of the label to the targeted rectangle\r\n    label.frame = labelRect;\r\n    \r\n    // Try all font sizes from largest to smallest font size\r\n    int fontSize = 100;\r\n    int minFontSize = 5;\r\n    \r\n    // Fit label width wize\r\n    CGSize constraintSize = CGSizeMake(label.frame.size.width, MAXFLOAT);\r\n    \r\n    do {\r\n        // Set current font size\r\n        label.font = [UIFont fontWithName:label.font.fontName size:fontSize];\r\n        \r\n        // Find label size for current font size\r\n        CGRect textRect = [[label text] boundingRectWithSize:constraintSize\r\n                                                     options:NSStringDrawingUsesLineFragmentOrigin\r\n                                                  attributes:@{NSFontAttributeName:label.font}\r\n                                                     context:nil];\r\n        \r\n        CGSize labelSize = textRect.size;\r\n        \r\n        // Done, if created label is within target size\r\n        if( labelSize.height <= label.frame.size.height )\r\n            break;\r\n        \r\n        // Decrease the font size and try again\r\n        fontSize -= 1;\r\n        \r\n    } while (fontSize > minFontSize);\r\n}\r\n~~~\r\n\r\n但是我觉得不一定能够适用于YYLabel。  希望ibireme能够讨论一下，看看如何解决这个问题。\r\n\r\n感谢。"}}