swift - 在 Swift 中为 UIButton 的文本添加基本的发光效果
问题描述
我的问题很直接。我的目标是快速为按钮添加基本的发光效果。我希望文本发光,而不是整个按钮框。我附上了一张图片作为例子来说明我的目标。
我在别处看过,但通常只找到不是我想要的动画。抱歉,图片质量很差。
我目前正在使用此代码,但我的设置按钮出现非常微弱的光芒,我怎样才能使它更强大:
import UIKit
extension UIView {
enum GlowEffect: Float {
case small = 0.4, normal = 2, big = 30
}
func doGlowAnimation(withColor color: UIColor, withEffect effect: GlowEffect = .normal) {
layer.masksToBounds = false
layer.shadowColor = color.cgColor
layer.shadowRadius = 0
layer.shadowOpacity = 1
layer.shadowOffset = .zero
let glowAnimation = CABasicAnimation(keyPath: "shadowRadius")
glowAnimation.fromValue = 20 // effect.rawValue
glowAnimation.toValue = 20
glowAnimation.fillMode = .removed
glowAnimation.repeatCount = .infinity
layer.add(glowAnimation, forKey: "shadowGlowingAnimation")
}
}
改变强度不会在单个字母附近产生强烈的色彩效果
解决方案
推荐阅读
- dart - 有没有 *?飞镖中的操作员?
- azure-data-studio - 将 settings.json 移动到 Azure Data Studio 的其他文件夹
- amazon-redshift - Redshift 警报 - HealthStatus 和 MaintenanceMode 复合
- java - 第一行中的eclipse java代码注释文本
- c# - left join linq 与 where 子句
- database - 第三范式 (3NF)
- clojure - 练习 Clojure 练习
- javascript - 如何在错误和退出后保持 Golang WebAssembly 实例运行(代码:2)
- javascript - 强制 IFrame 加载网站的移动版本
- python - 在多层 img 输入上需要来自 tensorflow 的帮助或有关 keras 的信息