Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class TemplateView: UIView {
- let picture: UIImageView
- var touch: (() -> Void)?
- convenience init() {
- self.init(frame: CGRect.zero)
- }
- override init(frame: CGRect) {
- picture = UIImageView(image: nil)
- picture.contentMode = .scaleAspectFill
- picture.backgroundColor = UIColor.lightGray
- super.init(frame: frame)
- addSubview(picture)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- /// Используем вместо Autolayout. Обязательно вызываем super.
- override func layoutSubviews() {
- super.layoutSubviews()
- picture.frame = bounds
- }
- /// Перехватываем тачи. Обязательно вызываем super.
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- super.touchesBegan(touches, with: event)
- touch?()
- }
- override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
- super.touchesEnded(touches, with: event)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement