InitialImageView 1.0.2

InitialImageView 1.0.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最后发布2016 年 5 月
SPM支持 SPM

Zac Kwan 维护。



  • Zac Kwan

InitialImageView

Build Status

InitialImageView 是 UIImageView 的子类,允许用户将初始字母或名称设置为占位图,就像在 iOS 联系人中看到的那样。

Screenshot 1

Screenshot 2

安装

手动安装

只需将 InitialImageView.swift 拖放到您的项目中即可。

示例

1) 在 ViewController 中包含 IBOutlet 的 Storyboard

@IBOutlet weak var initialImageView: InitialImageView!

override func viewDidLoad() {
  super.viewDidLoad()
  initialWithFontImageView.setImageWithInitial("YW", backgroundColor: UIColor.greenColor())
}

2) 从代码中实现

override func viewDidLoad() {
  super.viewDidLoad()
  let initialImageView = InitialImageView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
  initialWithFontImageView.setImageWithInitial("YW", backgroundColor: UIColor.greenColor())
}

用法

1) 将您的 UIImageView 更改为 InitialImageView

2) 调用以下任何函数之一来设置 InitialImageView 的图像

func setImageWithFirstName(firstName: String, lastName: String, backgroundColor: UIColor = UIColor.darkGrayColor(), randomColor: Bool = false)
func setImageWithInitial(initial: String, backgroundColor: UIColor = UIColor.darkGrayColor(), randomColor: Bool = false)
func setImageWithInitial(initial: String, backgroundColor: UIColor = UIColor.darkGrayColor(), randomColor: Bool = false)

backgroundColor 的默认值是 UIColor.darkGrayColor(),但是可以在调用函数时通过任何 UIColor 来设置。

randomColor 的默认值是 false。将 randomColor 设置为 true 时,将忽略 backgroundColor 参数并生成一个不是“接近”白色的随机 UIColor。

3) 属性

如需修改默认值,可以设置以下属性

var fontResizeValue: CGFloat
var font: UIFont
var isCircle: Bool

fontResizeValue 用于根据 self.bounds 计算字体大小

font 将用于绘制要设置为 InitialImageView 的初始 UIImage。在这里设置字体大小对 'font' 不会产生任何影响

isCircle 是一个布尔值,用于确定 InitialImageView 是否应该是圆形

关于

该项目受到 Objective-c 中 UIImageView+Letters 的启发。我多次在 Objective-c 项目中使用这些 Pods。我决定用一些更改将其写成 Swift,并将其改写为子类。

许可证

InitialImageView 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE