Irfan DANISH
Irfan DANISH

Reputation: 8489

UIButton title label transform cuts off label

I am creating a UIButton with interface builder of size 30px width and 164px height.

I want to rotate title of UIButton to 90 degrees.

I am using following code for rotation

// leftNavBtn1 is a UIButton
self.leftNavBtn1.titleLabel.transform = CGAffineTransformMakeRotation(-M_PI / 2);

The problem is after rotation the label cuts off. I have tried to programatically set title but its not work.

I want to achieve like this

enter image description here

What i am getting

enter image description here

Upvotes: 1

Views: 1088

Answers (2)

Benz
Benz

Reputation: 463

Maybe it's stupid, but have you tried creating a label over your button and then apply the same rotation?

It's not elegant but can work

Upvotes: 0

Pieter
Pieter

Reputation: 17705

The titleLabel property is primarily used to configure the text of the button, not its bounds.

I don't think you can achieve what you want to achieve.
If I understand you correctly, you make a button with a small width and big height in interface builder, then set the transformation on the label of the button to 90º, and then expect the button to behave as if the width became the height and vice versa.

I suppose you could still set the button in interface builder, but make it horizontal, as if it's rotated -90º, and then set the transformation on the UIButton in viewDidLoad

Upvotes: 1

Related Questions