简体   繁体   English

UILabel圆角在iOS 7.1中变得清晰

[英]UILabel rounded corners turn out sharp in iOS 7.1

Since the update to iOS7.1 the UILabels in my app have changed appearance. 自iOS7.1更新以来,我的应用程序中的UILabels已经改变了外观。 Prior to the OS update, all my UILabels had rounded corners as was my intention. 在操作系统更新之前,我的所有UILabel都有圆角,这是我的意图。 With iOS7.1 they now all have sharp corners. 在iOS7.1中,它们现在都有尖角。

I insert the code I use below. 我插入下面使用的代码。 Any help on how to restore the UILabels to my original appearance will be appreciated. 任何有关如何将UILabels恢复到我原始外观的帮助将不胜感激。



Top of the implementation file of the view controller: 视图控制器的实现文件的顶部:

#import <QuartzCore/QuartzCore.h>

The code for the creation of the UILabel. 用于创建UILabel的代码。 I have marked (what I consider) the relevant line with a comment. 我用评论标记了(我考虑的)相关行。

    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];

Set theLabel.clipsToBounds = YES , or theLabel.layer.masksToBounds = YES . 设置theLabel.clipsToBounds = YEStheLabel.layer.masksToBounds = YES Either will work. 要么工作。

use this 用这个

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM