Created
August 1, 2020 22:14
-
-
Save MojtabaHs/30e307aeada3b409fe20dcbb6cbceac6 to your computer and use it in GitHub Desktop.
A class for masking any subclass of UIView with an Image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBDesignable | |
class MaskableView: <#AnyUIViewSubclass#> { | |
var maskImageView = UIImageView() | |
@IBInspectable | |
var maskImage: UIImage? { | |
didSet { | |
maskImageView.image = maskImage | |
updateView() | |
} | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
updateView() | |
} | |
func updateView() { | |
if maskImageView.image != nil { | |
maskImageView.frame = bounds | |
mask = maskImageView | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment