Question

-(NSMutableAttributedString *) masBlueBoldColorString:(NSString *) theString
{



    UIFont * italicSystemFont =  [UIFont fontWithName:@"HelveticaNeue-Bold" size:sizeOfFonthighLightSomeStuff];


    CTFontRef font = CTFontCreateWithName((__bridge  CFStringRef)italicSystemFont.fontName, italicSystemFont.pointSize, NULL);
    NSRange rangeHighlight = NSMakeRange(0, theString.length);

    NSMutableAttributedString * mutableAttributedString = [[ NSMutableAttributedString alloc]initWithString:theString];

    if (font) {
        [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge  id)font range:rangeHighlight];
        CFRelease(font);
    }

    return mutableAttributedString;
}

There are some problem with this code....

I want the "font" to be returned by a method. Do we have CFAutoRelease? If we do not need to use font at all it'll be even better

Was it helpful?

Solution

- (UIFont*)myFontMethod
{
    return [UIFont fontWithName:@"HelveticaNeue-Bold" size:sizeOfFonthighLightSomeStuff];
}

-(NSMutableAttributedString *) masBlueBoldColorString:(NSString *) theString
{
    UIFont * font = [self myFontMethod];

    NSMutableAttributedString * mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:theString];

    if (font) {
        [mutableAttributedString addAttribute:NSFontNameAttribute value:font];
    }

    return mutableAttributedString;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top