Skip to content

Commit b13a21b

Browse files
Add CustomCameraViewController
1 parent 9c68803 commit b13a21b

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Example App/iOS Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
95A612BC27D5092700C8E6AB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95A612BB27D5092700C8E6AB /* Assets.xcassets */; };
1414
95A612BF27D5092700C8E6AB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95A612BD27D5092700C8E6AB /* LaunchScreen.storyboard */; };
1515
95A612C927D50A9000C8E6AB /* SPQRCode in Frameworks */ = {isa = PBXBuildFile; productRef = 95A612C827D50A9000C8E6AB /* SPQRCode */; };
16+
95E76BE527D62492003667A6 /* CustomCameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E76BE427D62492003667A6 /* CustomCameraViewController.swift */; };
1617
/* End PBXBuildFile section */
1718

1819
/* Begin PBXFileReference section */
@@ -24,6 +25,7 @@
2425
95A612BE27D5092700C8E6AB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2526
95A612C027D5092700C8E6AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2627
95A612C627D50A3400C8E6AB /* SPQRCode */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SPQRCode; path = ..; sourceTree = "<group>"; };
28+
95E76BE427D62492003667A6 /* CustomCameraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCameraViewController.swift; sourceTree = "<group>"; };
2729
/* End PBXFileReference section */
2830

2931
/* Begin PBXFrameworksBuildPhase section */
@@ -62,6 +64,7 @@
6264
95A612B227D5092600C8E6AB /* AppDelegate.swift */,
6365
95A612B427D5092600C8E6AB /* SceneDelegate.swift */,
6466
95A612B627D5092600C8E6AB /* ViewController.swift */,
67+
95E76BE427D62492003667A6 /* CustomCameraViewController.swift */,
6568
95A612BB27D5092700C8E6AB /* Assets.xcassets */,
6669
95A612BD27D5092700C8E6AB /* LaunchScreen.storyboard */,
6770
95A612C027D5092700C8E6AB /* Info.plist */,
@@ -149,6 +152,7 @@
149152
isa = PBXSourcesBuildPhase;
150153
buildActionMask = 2147483647;
151154
files = (
155+
95E76BE527D62492003667A6 /* CustomCameraViewController.swift in Sources */,
152156
95A612B727D5092600C8E6AB /* ViewController.swift in Sources */,
153157
95A612B327D5092600C8E6AB /* AppDelegate.swift in Sources */,
154158
95A612B527D5092600C8E6AB /* SceneDelegate.swift in Sources */,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// ViewController.swift
3+
// iOS Example
4+
//
5+
// Created by Nikita Somenkov on 06.03.2022.
6+
//
7+
8+
import Foundation
9+
import SPQRCode
10+
import UIKit
11+
import AVFoundation
12+
13+
final class CustomCameraViewController: SPQRCameraViewController {
14+
15+
private lazy var frameView = UIView()
16+
private lazy var label = UILabel()
17+
18+
override func viewDidLoad() {
19+
frameView.layer.cornerRadius = 8
20+
frameView.layer.borderColor = UIColor.white.cgColor
21+
frameView.layer.borderWidth = 3.0
22+
frameView.layer.shadowColor = UIColor.black.cgColor
23+
frameView.layer.shadowOpacity = 0.3
24+
25+
label.font = .systemFont(ofSize: 17)
26+
label.textColor = .white
27+
label.textAlignment = .center
28+
label.layer.shadowColor = UIColor.black.cgColor
29+
label.layer.shadowOpacity = 0.3
30+
31+
customFrameView = frameView
32+
customPreviewView = UIView()
33+
34+
super.viewDidLoad()
35+
36+
view.addSubview(label)
37+
38+
label.translatesAutoresizingMaskIntoConstraints = false
39+
NSLayoutConstraint.activate([
40+
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32),
41+
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -32),
42+
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 32),
43+
])
44+
}
45+
46+
override func updatePreviewView(for object: AVMetadataMachineReadableCodeObject) {
47+
label.text = object.stringValue
48+
}
49+
50+
}

0 commit comments

Comments
 (0)