自从更新到iOS7.1以来,我的应用程序中的UILabels已经改变了外观。在操作系统更新之前,我所有的UILabels都有圆角,这是我的意图。在iOS7.1中,它们现在都有尖角。
我在下面插入我使用的代码。任何关于如何将UILabels恢复到我原来的外观的帮助将不胜感激。
视图控制器的实现文件顶部:
#import <QuartzCore/QuartzCore.h>
用于创建 UILabel 的代码。我已经用评论标记了(我认为的)相关行。
CGRect labelRect = CGRectMake(20, 20, 200, 100);
NSString *theText = [self info];
CGSize size = [theText sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
UILabel *theLabel = [[UILabel alloc] initWithFrame:labelRect];
[theLabel setNumberOfLines:0];
[theLabel setText:theText];
[[theLabel layer] setCornerRadius:15]; // THIS IS THE RELEVANT LINE
// For iOS7
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
[theLabel setBackgroundColor:[UIColor whiteColor]];
[[self view] addSubview:theLabel];
设置theLabel.clipsToBounds = YES
或 theLabel.layer.masksToBounds = YES
。两者都会起作用。
使用这个
CGRect labelRect = CGRectMake(20, 20, 200, 100);
NSString *theText = [self info];
CGSize size = [theText sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
UILabel *theLabel = [[UILabel alloc] initWithFrame:labelRect];
[theLabel setNumberOfLines:0];
[theLabel setText:theText];
[[theLabel layer] setCornerRadius:15]; // THIS IS THE RELEVANT LINE
[theLabel.layer setMasksToBounds:YES]; ///missing in your code
// For iOS7
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
[theLabel setBackgroundColor:[UIColor whiteColor]];
[[self view] addSubview:theLabel];