簡體   English   中英

在iOS中將文字旋轉90度

[英]rotate text by 90 degrees in iOS

  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度角顯示。 有什么方法可以解決此問題(無需切換到標簽,因為這需要進行很多更改)?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM