Last active
August 29, 2015 14:24
-
-
Save lihei12345/bbf24f729cfea49bb010 to your computer and use it in GitHub Desktop.
fix multi-line UILabel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // iOS8之下,Auto Layout中使用多行Label的时候,需要手工设置preferredMaxLayoutWidth才能work,iOS8之后则不需要; | |
| // 最低支持版本变为iOS8的时候,改用UILabel即可 | |
| // 1. http://stackoverflow.com/questions/25398312/automatic-preferred-max-layout-width-is-not-available-on-ios-versions-prior-to-8 | |
| // 2. http://stackoverflow.com/questions/17491376/ios-autolayout-multi-line-uilabel | |
| #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0) | |
| @interface AutolayoutFixLabel : UILabel | |
| @end | |
| #endif | |
| #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0) | |
| @implementation AutolayoutFixLabel | |
| - (void)setBounds:(CGRect)bounds | |
| { | |
| if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.99) { | |
| self.preferredMaxLayoutWidth = bounds.size.width; | |
| } | |
| [super setBounds:bounds]; | |
| } | |
| @end | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment