Search code examples
iosuilabelnsattributedstring

NSAttributedString Not Working - Does not appear when compiled for Distribution


This code works in the simulator and connected devices via USB port. It does not work when the app is compiled for distribution (Target:IOS 6.1, Xcode 5.1.1) and downloaded as .ipa

Any idea why? Has anyone seen this? Have a workaround?

#import "UILabel+UILabel_decoratedText.h"

@implementation UILabel (UILabel_decoratedText)

+ (UILabel *)decoratedText:(NSString *)string
                        font:(UIFont *)font
                       color:(UIColor *)color
                   container:(CGRect)container
              shadowOffset:(CGSize)shadowOffsetSize
               shadowColor:(UIColor *)shadowColor
          shadowBlurRadius:(CGFloat)blurRadius
                    tag:(NSUInteger)tagInteger
{

    CGSize size = [string sizeWithFont:font constrainedToSize:container.size lineBreakMode:NSLineBreakByWordWrapping];

    UILabel *label = [[UILabel alloc]
                       initWithFrame:CGRectMake(container.origin.x, container.origin.y, container.size.width, size.height)];
    label.text = string;
    label.font = font;
    label.textColor = color;
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.backgroundColor = [UIColor clearColor];
    label.tag = tagInteger;

    NSShadow *shadow = [NSShadow new];
    [shadow setShadowColor: shadowColor];
    [shadow setShadowOffset: shadowOffsetSize]; // CGSizeMake(-1.0f, 1.0f)
    [shadow setShadowBlurRadius: blurRadius];

    NSAttributedString *attributedString;

    if ((string != nil) && (![string isEqualToString:@""])) {
        NSDictionary *dictionary = @{ NSForegroundColorAttributeName:color,
                                       NSFontAttributeName : font,
                                       NSShadowAttributeName: shadow
                                       };
        attributedString = [[NSAttributedString alloc] initWithString:string attributes:dictionary];
        label.attributedText = attributedString;
    }
    return label;
}

@end

Solution

  • After running into a bunch of issues with multi-line UILabel and NSAttributedString I changed my UILabel to UITextView and everything worked. You can search SO And Google for UILabel, NSAttributedString and issues and you'll get a few hits.