iOS自定义控件 - 奇怪的文字

时间:2014-05-04 20:52:52

标签: ios text drawrect

我已根据UIView实施了自定义控件(图表)。覆盖drawRect。 现在尝试使用此行添加标签:

[[[barLabels objectAtIndex:i] objectForKey:@"day"] drawInRect:someRect withFont:[UIFont systemFontOfSize:10.0] lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];

但正如你在图片中看到的那样:

http://i58.tinypic.com/15ppvg2.png

文本以非常奇怪的方式显示。有什么想法吗? 附: drawRect方法的完整来源:

- (void)drawRect:(CGRect)rect
{

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    UIGraphicsPushContext(ctx);
    CGContextSetShouldSmoothFonts(ctx, true);

    for(int i = 0; i < [barRects count]; i++)
    {
        CGRect someRect = [[barRects objectAtIndex:i] CGRectValue];

        [self drawBar:someRect context:ctx];


        [[barValues objectAtIndex:i] drawInRect:CGRectMake(someRect.origin.x + 0.5f, someRect.origin.y + someRect.size.height - margin - hAxisValuesMargin + 0.5f, someRect.size.width, someRect.size.height) withFont:[AppController brandFontLight:8] lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];

        [[[barLabels objectAtIndex:i] objectForKey:@"day"] drawInRect:someRect withFont:[UIFont systemFontOfSize:10.0] lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];

     [[[barLabels objectAtIndex:i] objectForKey:@"month"] drawInRect:CGRectMake(someRect.origin.x, someRect.origin.y + hAxisFontSize, someRect.size.width, someRect.size.height) withFont:[AppController brandFontBold:10] lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];
    }


    UIGraphicsPopContext();

}

0 个答案:

没有答案