UILabel上的阴影不会出现

时间:2011-08-30 22:15:21

标签: iphone objective-c cocoa-touch uilabel quartz-graphics

我想为我的UILabel添加一点阴影,但它没有显示出来。

companyLabel.textAlignment = UITextAlignmentLeft;
        companyLabel.font = [UIFont fontWithName:@"Arial" size:13];
        companyLabel.adjustsFontSizeToFitWidth = YES;
        companyLabel.minimumFontSize = 10.0; 
        companyLabel.backgroundColor = [UIColor clearColor];
        companyLabel.textColor = [UIColor colorWithRed:103.0/255.0 green:103.0/255.0 blue:103.0/255.0 alpha:1.0];
        companyLabel.layer.shadowColor = [[UIColor colorWithRed:241.0/255.0 green:241.0/255.0 blue:241.0/255.0 alpha:1.0] CGColor];
        companyLabel.layer.shadowOffset = CGSizeMake(0.0, -1.0);
        companyLabel.highlightedTextColor = [UIColor whiteColor];

1 个答案:

答案 0 :(得分:21)

您没有设置shadowOpacity,默认为0.0。您需要将其设置为其他内容以使阴影显示出来。但是,由于CALayer拥有自己的UILabelshadowColor属性,因此我们没有理由立即触摸shadowOffset

companyLabel.shadowColor = [UIColor colorWithRed:241.0/255.0 green:241.0/255.0 blue:241.0/255.0 alpha:1.0];
companyLabel.shadowOffset = CGSizeMake(0.0, -1.0);