以编程方式向 UIButton 标签添加阴影

Programmatically adding a shadow to a UIButton label(以编程方式向 UIButton 标签添加阴影)

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

问题描述

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:

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 标签添加阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:以编程方式向 UIButton 标签添加阴影

基础教程推荐