How to display text using Quartz on the iPhone?

前端 未结 2 1573
一生所求
一生所求 2021-02-09 05:02

I\'ve been trying to display text using a Quartz context, but no matter what I\'ve tried I simply haven\'t had luck getting the text to display (I\'m able to display all sorts o

2条回答
  •  臣服心动
    2021-02-09 05:19

    Here is a fragment of code that I'm using.

    UIColor *mainTextColor = [UIColor whiteColor];
    [mainTextColor set];
    drawTextLjust(@"Sample Text", 8, 50, 185, 18, 16);
    

    And:

    static void drawTextLjust(NSString* text, CGFloat y, CGFloat left, CGFloat right,
                              int maxFontSize, int minFontSize) {
        CGPoint point = CGPointMake(left, y);
        UIFont *font = [UIFont systemFontOfSize:maxFontSize];
        [text drawAtPoint:point forWidth:right - left withFont:font
           minFontSize:minFontSize actualFontSize:NULL
           lineBreakMode:UILineBreakModeTailTruncation
           baselineAdjustment:UIBaselineAdjustmentAlignBaselines];
    }
    

提交回复
热议问题