简体   繁体   English

iphone-带有内部发光的UIButton

[英]iphone - UIButton with inner glow

I want to create a rectangular rounded corner button with an inner glow. 我想创建一个带有内部辉光的矩形圆角按钮。 I hear some recommendations about adding subviews, but i'm worried subviews will cover the text in my button. 我听到了一些有关添加子视图的建议,但是我担心子视图会覆盖我按钮中的文字。

How do I achieve inner glow without blocking out the text or background icon image? 如何在不遮挡文本或背景图标图像的情况下实现内部发光?

Make an image of what you want, then import it into your project. 制作所需图像,然后将其导入项目中。 Set the type of your button to custom, and then set the image to the glowing image you made. 将按钮的类型设置为“自定义”,然后将图像设置为您制作的发光图像。

You can do this(it's not exactly a glow on the button but on the label of the button). 您可以执行此操作(按钮上并非完全发光,而是按钮的标签上发光)。 The effect is very similar. 效果非常相似。 First 第一

#import <QuartzCore/QuartzCore.h>

and then 接着

UIColor *color = button.currentTitleColor;
theButton.titleLabel.layer.shadowColor = [color CGColor];
theButton.titleLabel.layer.shadowRadius = 4.0f;
theButton.titleLabel.layer.shadowOpacity = .9;
theButton.titleLabel.layer.shadowOffset = CGSizeZero;
theButton.titleLabel.layer.masksToBounds = NO;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM