JNGradientLabel 1.0.3

JNGradientLabel 1.0.3

Joseph Newton 维护。



  • Joe Newton

Gradient Label

JNGradientLabel

Codacy Badge License MIT CocoaPods Compatible Carthage Compatible Platform Code Coverage

Swift Package Xcode Project Cocoapods Carthage

一个使用渐变色作为其文本或背景颜色的 UILabel 子类。

安装

JNGradientLabel 通过 CocoaPodsCarthageSwift 包管理器 提供。

要使用 CocoaPods 安装,请简单地将以下行添加到您的 Podfile 中:

pod 'JNGradientLabel'

要使用 Carthage 安装,请简单地将以下行添加到您的 Cartfile 中:

github "SomeRandomiOSDev/JNGradientLabel"

要使用 Swift 包管理器安装,请将以下行添加到您的 Package.swift 文件的 dependencies 中:

.package(url: "https://github.com/SomeRandomiOSDev/JNGradientLabel.git", from: "1.0.0")

使用方法

首先在源文件顶部导入 JNGradientLabel

Swift

import JNGradientLabel

Objective-C

@import JNGradientLabel;

初始化标签后(从 Storyboard/XIB 或手动),调用以下方法之一:

Swift

// To produce an `Axial` (Linear) gradient
label.setAxialGradientParameters(startPoint: startPoint,
                                   endPoint: endPoint,
                                     colors: gradientColors,
                                  locations: gradientlocations,
                                    options: ... /* Optional CGGradientDrawingOptions parameter */)

或者

// To produce a `Radial` gradient
label.setRadialGradientParameters(startCenter: startCenter,
                                  startRadius: startRadius,
                                    endCenter: endCenter,
                                    endRadius: endRadius,
                                       colors: gradientColors,
                                    locations: gradientlocations,
                             radiiScalingRule: ... /* Optional RadialGradientRadiiScalingRule parameter */,
                                      options: ... /* Optional CGGradientDrawingOptions parameter */)

Objective-C

// To produce an `Axial` (Linear) gradient
[label setAxialGradientParametersWithStartPoint:startPoint 
                                       endPoint:endPoint 
                                         colors:gradientColors 
                                      locations:gradientLocations
                                        options:gradientDrawingOptions];

或者

// To produce a `Radial` gradient
[label setRadialGradientParametersWithStartCenter:startCenter 
                                      startRadius:startRadius 
                                        endCenter:endCenter 
                                        endRadius:endRadius 
                                           colors:gradientColors 
                                        locations:gradientLocations 
                                 radiiScalingRule:radiiScalingRule 
                                          options:gradientDrawingOptions];

这就是全部了!

默认情况下,标签会以文本颜色绘制渐变。标签还支持绘制文本的背景渐变。为此,只需将 textGradientLocation 属性设置为以下内容:

Swift

label.textGradientLocation = .background

Objective-C

label.textGradientLocation = TextGradientLocationBackground;

或者

[label setTextGradientLocation:TextGradientLocationBackground];

截图

前景轴向渐变: 前景轴向渐变

前景径向渐变: 前景径向渐变

背景轴向渐变: 背景轴向渐变

背景径向渐变: 背景径向渐变

贡献

如果您需要特定功能或遇到问题,请提交问题。如果您自己扩展了 JNGradientLabel 的功能或想自己修复错误,请提交一个拉取请求。

作者

Joe Newton, [email protected]

许可协议

JNGradientLabel 采用 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。