Skip to content

Instantly share code, notes, and snippets.

@kentakang
Created December 15, 2022 13:23
Show Gist options
  • Save kentakang/7829d4c837900231b93ab8fbeb6628cc to your computer and use it in GitHub Desktop.
Save kentakang/7829d4c837900231b93ab8fbeb6628cc to your computer and use it in GitHub Desktop.
import React
import UIKit
class SecureImageView: UIView {
@objc var url: String = "" {
didSet {
do {
let imageUrl = URL(string: url)
let data = try Data(contentsOf: imageUrl!)
let image = UIImage(data: data)
imageView.image = image
let imageWidth = image!.size.width
let imageHeight = image!.size.height
let viewWidth = UIScreen.main.bounds.width
let ratio = viewWidth / imageWidth
let scaledHeight = imageHeight * ratio
imageView.frame = CGRect(x: 0, y: 0, width: viewWidth, height: scaledHeight)
self.frame = CGRect(x: 0, y: 0, width: viewWidth, height: scaledHeight)
let field = UITextField()
field.isSecureTextEntry = true
imageView.addSubview(field)
imageView.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.first?.addSublayer(imageView.layer)
} catch {
print(error)
}
}
}
var imageView: UIImageView!
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
private func setupView() {
imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
self.addSubview(imageView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment