开发者

What is UILabel's vertical alignment algorithm?

There's ample discussion here on SO about Apple's failure to provide vertical alignment APIs for UILabel, but how does the actual vertical alignment work? Is the bounding box of the string (cf. sizeWithFont) ce开发者_C百科ntered? Or the x-height of the font (or the cap height?), so that the baseline stays the same regardless of ascenders and descenders? Or what?


Here is the code you can use to do vertical alignment of the UILabel. I do not see any apple's failure in providing API to you. You have to use label.transform = CGAffineTransformMakeRotation (-M_PI/2); You have total control on height/width and alignment. Hope this helps..

    rect = CGRectMake(0, 5, 130, 30);
    label = [[UILabel alloc] initWithFrame:rect];
    label.tag =1;
    label.font = [UIFont systemFontOfSize:15];
    label.adjustsFontSizeToFitWidth = NO;
    label.textAlignment = UITextAlignmentLeft;
    label.textColor = [UIColor whiteColor];
    label.transform = CGAffineTransformMakeRotation (-M_PI/2);
    label.backgroundColor = [UIColor colorWithRed:0.48 green:0.62 blue:0.79 alpha:1.0];
    [yourview or self addSubview:label];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜