ios - 如何在swift上更改pdf图像颜色?
问题描述
我添加了一个按钮并设置了一个 pdf 图像。我需要更改 pdf 图像颜色。能做到吗?
解决方案
您可以使用此扩展方法设置图像颜色,
import UIKit
extension UIButton {
public func setImage(color: UIColor, for state: UIControl.State) {
let image = self.image(for: state)
self.setImage(image?.withRenderingMode(.alwaysTemplate), for: state)
self.tintColor = color
}
}
用法
yourButton.setImage(color: .red, for: .normal)
推荐阅读
- swiftui - SwiftUI - IOS 15 - 文本 .mimimumScaleFactor - 总是被应用
- firebase - 如何从 Flutter 和 Firestore 中“Y”集合的文档 ID 查询“X”集合的文档
- python - 基于列唯一值创建新数据框
- flutter - Flutter:将输出值增加 1 - 但仅在相应创建的小部件中
- reactjs - React Native View Component 文档中缺少 Layout Props
- javascript - 单击时将图标添加到图像
- javascript - 使用异步、Foreach 和 arguments.callee
- c# - ASP.NET Core MVC:自定义 HtmlHelper 添加部分
- html - 如何在导航栏左侧放置文本而不影响右侧按钮?
- stepper - 你能在断电期间在 A4988 中保留微步吗