我正在嘗試使用石英2d繪製一個字符串。自定義字體。保持字體寬度相同
我正在做的是,我正在繪製字符串的每個字母,因爲每個字母都有與其關聯的特殊屬性,通過將每個字母轉換爲新字符串。
字符串被打印,但字母之間的空間不統一。看起來很難看。 我讀了一些關於使用自定義字體的東西。但我沒有想法,如果我能做到的話! 我的代碼在這裏。
- (void) drawRect : (CGRect)rect{
NSString *[email protected]"My Name Is Adam";
float j=0;
const char *charStr=[string cStringUsingEncoding: NSASCIIStringEncoding];
for(int i=0;i<strlen(charStr);i++)
{
NSString *str=[NSString stringWithFormat:@"%c",charStr[i]];
const char *s=[str cStringUsingEncoding:NSASCIIStringEncoding];
NSLog(@"%s",s);
CGContextRef context=[self getMeContextRef];
CGContextSetTextMatrix (context,CGAffineTransformMakeScale(1.0, -1.0)) ;
CGContextSelectFont(context, "Arial", 24, kCGEncodingMacRoman);
//CGContextSetCharacterSpacing (context, 10);
CGContextSetRGBFillColor (context, 0,0,200, 1);
CGContextSetTextDrawingMode(context,kCGTextFill);
CGContextShowTextAtPoint(context, 80+j,80,s,1);
j=j+15;
}
}
在輸出'我的名字是亞當'被打印但字母之間的空間不統一。有什麼辦法讓空間變得統一!
'NSAttributedString'尚未在iPhone上提供。 – 2010-05-13 10:51:30
呵呵,我沒注意! 'CFAttributedString'在那裏,但沒有API來處理它的繪圖......有趣! – mohsenr 2010-05-13 16:15:48