以编程方式将阴影添加到UIButton标签 [英] Programmatically adding a shadow to a UIButton label

查看:123
本文介绍了以编程方式将阴影添加到UIButton标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在没有运气的情况下为按钮标签添加1px黑色阴影。我试过这个: self.setTitleShadowOffset = CGSizeMake(0,-1); 但是我得到:

I'm trying to add a 1px black drop shadow to a button label with no luck. I've tried this:self.setTitleShadowOffset = CGSizeMake(0, -1); but I get:


请求成员'setTitleShadowOffset'在非结构或联合的东西

Request for member 'setTitleShadowOffset' in something not a structure or union

任何建议都非常棒,谢谢!

Any suggestions would be fantastic thanks!

推荐答案

其他答案没有正确设置阴影颜色(我怀疑他们没有注意到因为他们试图设置阴影颜色阴影颜色默认为黑色。)

The other answers do not properly set the shadow color (I suspect they didn't notice because they were trying to set the shadow color to what it is by default, black.)

此代码可以为我的按钮文本添加白色阴影:

This code worked for me to add a white shadow to the text of my button:

myButton.titleLabel.shadowOffset = CGSizeMake(0, 1);
[myButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];

这篇关于以编程方式将阴影添加到UIButton标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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