Skip to content

Instantly share code, notes, and snippets.

@lihei12345
Last active August 29, 2015 14:24
Show Gist options
  • Save lihei12345/bbf24f729cfea49bb010 to your computer and use it in GitHub Desktop.
Save lihei12345/bbf24f729cfea49bb010 to your computer and use it in GitHub Desktop.
fix multi-line UILabel
// 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