相关疑难解决方法(0)

如何更改UILabel/UIFont的字母间距?

我已经搜索了负载,但找不到答案.

我有一个正常的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];
Run Code Online (Sandbox Code Playgroud)

我希望字母之间的水平间距更紧,同时保持字体大小.

有没有办法做到这一点?这应该是一件非常基本的事情.

干杯,安德烈

更新:

所以我被迫这样做:

- (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, …
Run Code Online (Sandbox Code Playgroud)

iphone xcode spacing uilabel uifont

38
推荐指数
3
解决办法
5万
查看次数

标签 统计

iphone ×1

spacing ×1

uifont ×1

uilabel ×1

xcode ×1