2014-02-10 137 views
0
NSString *strFromInt = [NSString stringWithFormat:@"%d",score]; 
    NSString *strFromInt2 = [NSString stringWithFormat:@"%ld",(long)highscore]; 
    CGContextRef gc = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBFillColor(gc, 0, 0, 0, 1); 
    UIFont *uif = [UIFont systemFontOfSize:32]; 
    NSString *combind = [NSString stringWithFormat:@"%@%@%@%@", str, strFromInt, str2, strFromInt2]; 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 
    CGContextRotateCTM(context, -(M_PI/2)); 
    CGContextRestoreGState(context); 
    [combind drawAtPoint:CGPointMake(100, 100) withAttributes:@{NSFontAttributeName:uif}]; 

我的代碼適用於打印高分,但是我的當前應用是橫向而非縱向,所以文本以90度角顯示。有沒有辦法解決這個問題(不需要切換到標籤,因爲這需要很多改變)?在iOS中將文本旋轉90度

回答

0

您是否嘗試過使用CGContextGetTextMatrix()來查看當前文本矩陣的外觀?文本矩陣被連接到當前的變換矩陣。也許它有一個你不想要的價值?