x和y是整數。iOS使用CGcontextshowtextatpoint爲某些字體的文本繪製矩形
int theSize = [caption.text length];
CGContextShowTextAtPoint(context, x, y, [caption.text UTF8String], theSize);
但是當我使用某些字體,字母顯示爲矩形:當我使用CGBitmapCreateContext發送自定義創建的上下文,然後用普通的字體使用它像ArialMT
下面的代碼工作正常。於是,我就做什麼其他堆棧溢出回答表明,這是使用CoreText:
// supposedly a solution to glyphs problem
CGContextSaveGState(context);
CGContextSetRGBFillColor(context, 0, 0, 0, .5);
[caption.text drawAtPoint:CGPointMake(x, y) withFont:caption.font];
CGContextRestoreGState(context);
但是,這只是給了我一個錯誤:9月7日十三點33分31秒...:CGContextShowGlyphsWithAdvances:無效的情況下爲0x0