使用原生 CoreGraphics 创建漂亮的图案。
这是 Jason Long 的 GeoPattern 的一个移植版本,最初是用 Ruby 编写的,用于使用 SVG。由于 SVG 在 Cocoa 项目中需要外部支持,因此这个版本使用 CoreGraphics。GeoPattern 仅创建一个性感视图。因为它只是一个 UIView,所以可以几乎在任何地方使用。
使用 Cocoapods。
pod 'GeoPattern', ~> 1.0.3
否则,将 GeoPattern 文件夹复制到您的项目,并在您的项目构建中包含安全框架。
您只需导入 GeoPattern.h
即可。
您可以使用 storyboard 创建 GeoPatternView,或者通过初始化一个新的 GeoPatternView。实际上只存在两种方法。
以下是一个基于字符串简单地生成模式的示例
generateWithString: (NSString *) string
使用预设选项基于字符串生成模式。
generateWithString: (NSString *) string andOptions: (NSDictionary*) options
kGeoPatternColor
: UIColor,确切的背景颜色kGeoPatternBaseColor
: UIColor,算法将对其进行编辑。色调和饱和度基于输入字符串。kGeoPatternType
- 您想要使用的模式类型。(请参见下文中的列表)这包括原始项目中的所有模式。每个模式都可以通过枚举访问。要使用特定类型的模式生成 GeoPatternView,只需将键添加到选项参数即可。
NSDictionary * options = @{
kGeoPatternType: [NSNumber numberWithInteger: GeoPatternXes,
kGeoPatternColor: [UIColor redColor]
};
[view generateFromString: @"Matthew" withOptions: options;]
GeoPatternOctogons
GeoPatternOverlappingcircles
GeoPatternPlussigns
GeoPatternXes
GeoPatternSinewaves
GeoPatternHexagons
GeoPatternOverlappingrings
GeoPatternPlaid
GeoPatternTriangles
GeoPatternSquares
GeoPatternConcentriccircles
GeoPatternDiamonds
GeoPatternTessellation
GeoPatternNestedsquares
GeoPatternMosaicsquares
GeoPatternChevrons