문제

I have been using PaintCode to draw some of the graphics within my app, some of the drawn elements have text that is drawn using "drawInRect". The text is always showing up black regardless of what I do to try and set the color.

here is the code where the text is created, and I am attempting to set the color:

       //// Rounded Rectangle Drawing
    UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, 0, 66, 66) cornerRadius: 15];
    [[NPSColor NPSPrimaryColor] setFill];
    [roundedRectanglePath fill];

    UIFont *helveticaFont = [UIFont fontWithName:@"AvenirNextCondensed-Bold" size:50];

    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    /// Set line break mode
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    /// Set text alignment
    paragraphStyle.alignment = NSTextAlignmentCenter;

    NSDictionary *attributes = @{NSFontAttributeName:helveticaFont,
                                 NSParagraphStyleAttributeName:paragraphStyle};


    //// Text Drawing
    CGRect textRect = CGRectMake(-4, -2.5, 74, 71.5);
    [[NPSColor whiteColor] set];
    [textContent drawInRect: CGRectInset(textRect, 0, 6) withAttributes:attributes];

}

The white color in the "text drawing" is what is not working properly. Thanks for the assistance.

도움이 되었습니까?

해결책

You need to set the color of the text in the "attributes" dictionary you pass in via:

[textContent drawInRect: CGRectInset(textRect, 0, 6) withAttributes:attributes];

My suggest would be:

NSDictionary *attributes = @{ NSFontAttributeName:helveticaFont,
                              NSParagraphStyleAttributeName:paragraphStyle,
                              NSForegroundColorAttributeName: [NPSColor whiteColor]}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top