增加占位图

This commit is contained in:
zjx 2025-05-28 11:31:00 +08:00
parent 16bfd15395
commit 64857ea501
8 changed files with 52 additions and 3 deletions

View File

@ -101,4 +101,8 @@ extension UIColor {
static func colorB5B5B5(alpha: CGFloat = 1) -> UIColor {
return UIColor(rgb: 0xB5B5B5, alpha: alpha)
}
static func colorC4C4C4(alpha: CGFloat = 1) -> UIColor {
return UIColor(rgb: 0xC4C4C4, alpha: alpha)
}
}

View File

@ -9,7 +9,14 @@ import UIKit
class VPImageView: UIImageView {
var placeholderColor = UIColor.gray
var placeholderColor = UIColor.colorC4C4C4()
private lazy var placeholderImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "placeholder_image_01"))
imageView.isHidden = true
imageView.contentMode = .scaleAspectFit
return imageView
}()
override init(frame: CGRect) {
super.init(frame: frame)
@ -36,7 +43,10 @@ class VPImageView: UIImageView {
self.layer.masksToBounds = true
if image == nil {
self.backgroundColor = self.placeholderColor
placeholderImageView.isHidden = false
}
addSubview(placeholderImageView)
}
override var image: UIImage? {
@ -48,7 +58,20 @@ class VPImageView: UIImageView {
self.backgroundColor = nil
}
}
if image == nil {
placeholderImageView.isHidden = false
} else {
placeholderImageView.isHidden = true
}
}
}
override func layoutSubviews() {
super.layoutSubviews()
placeholderImageView.frame = .init(x: 0, y: 0, width: self.bounds.width * (2 / 3), height: self.bounds.height * (2 / 3))
placeholderImageView.center = .init(x: self.bounds.width / 2, y: self.bounds.height / 2)
}
}

View File

@ -47,8 +47,8 @@ class VPSearchViewController: VPViewController {
vp_setupUI()
vp_addAction()
let tap = UITapGestureRecognizer(target: self, action: #selector(handleScreen))
self.view.addGestureRecognizer(tap)
// let tap = UITapGestureRecognizer(target: self, action: #selector(handleScreen))
// self.view.addGestureRecognizer(tap)
}

View File

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "加载占位图-切图图标@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "加载占位图-切图图标@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 MiB