水平UIButton中的垂直文本 [英] Vertical text in a Horizontal UIButton

查看:96
本文介绍了水平UIButton中的垂直文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在人像应用中使用了垂直的UIButton(只是宽度为60且高度为160的普通按钮)

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?

推荐答案

您可以在按钮上添加标签,然后按如下所示旋转标签:

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];

这篇关于水平UIButton中的垂直文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆