我已经搜索了很多负载,但找不到答案。
我有一个普通的 UILabel,这样定义的:
UILabel *totalColors = [[[UILabel alloc] initWithFrame:CGRectMake(5, 7, 120, 69)] autorelease];
totalColors.text = [NSString stringWithFormat:@"%d", total];
totalColors.font = [UIFont fontWithName:@"Arial-BoldMT" size:60];
totalColors.textColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0];
totalColors.backgroundColor = [UIColor clearColor];
[self addSubview:totalColors];
我希望字母之间的水平间距更紧密,同时保持字体大小。
有没有办法做到这一点?这应该是一件非常基本的事情。
干杯,安德烈
更新:
所以我被迫这样做:
- (void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSelectFont (context, "Arial-BoldMT", 60, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, -10);
CGContextSetTextDrawingMode (context, kCGTextFill);
CGContextSetRGBFillColor(context, 221/255.0, 221/255.0, 221/255.0, 221/255.0);
CGAffineTransform xform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
CGContextSetTextMatrix(context, xform);
char* result = malloc(17);
sprintf(result, "%d", totalNumber);
CGContextShowTextAtPoint (context, 0, 54, result, strlen(result));
}
但我需要把它对齐到右边。如果我知道绘制文本的宽度,我可以手动执行此操作,但事实证明几乎不可能找到它。
我已经阅读了有关 ATSU 的信息,但找不到任何示例。
这很糟糕:/