Search code examples
iosobjective-ctextuibuttonvertical-alignment

Vertical text in a Horizontal UIButton


I'm using a vertical UIButton in a portrait app (Just a normal button that is of width 60 and Height 160)

I want to put the label Vetically down the button instead of across it.

When I use the following code to rotate the label

    [workPackageButton.titleLabel setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

It rotates the label but the length seems to be constrained by the original width, so I get the ... abreviation in the middle. Is there an easy way round this?


Solution

  • You can add a Label on button and rotate the label as below:

    UILabel *lbl= [[UILabel alloc] initWithFrame:CGRectMake(button.frame.size.width*.3, button.frame.size.height*.5, button.frame.size.width,button.frame.size.height)];
    lbl.transform = CGAffineTransformMakeRotation(M_PI / 2);
    lbl.textColor =[UIColor whiteColor];
    lbl.backgroundColor =[UIColor clearColor];
    [button addSubview:lbl];