AR Overlay | iOS Document Scanner
Barcode AR Overlay
The Barcode AR Overlay can be enabled to display and select recognized barcodes in an augmented-reality fashion. Each recognized barcode will be presented on the barcode overlay by a colored frame and text. Styles of the frames and text can be customized for normal and selected barcodes. There is also a possibility to provide a custom view for each barcode. Barcodes can be selected by tapping on the barcode overlay or automatically by the tracking controller. All selected barcodes can be handled in the delegate methods of the tracking controller.
Example for integrating the Barcode Overlay Classic UI Component
- Swift
- Objective-C
import UIKit
import ScanbotSDK
// This is a simple, empty view controller which acts as a container and delegate for the SBSDKBarcodeScannerViewController conforming SBSDKBarcodeTrackingOverlayControllerDelegate.
class BarcodesOverlaySwiftViewController: UIViewController {
// The instance of the scanner view controller.
var scannerViewController: SBSDKBarcodeScannerViewController!
override func viewDidLoad() {
super.viewDidLoad()
// Create the SBSDKBarcodeScannerViewController instance
self.scannerViewController = SBSDKBarcodeScannerViewController(parentViewController: self,
parentView: self.view)
// Set self as a trackingViewController's delegate
self.scannerViewController.trackingOverlayController.delegate = self
// Enable the barcodes tracking overlay.
self.scannerViewController.isTrackingOverlayEnabled = true
// Get current tracking configuration object
let configuration = self.scannerViewController.trackingOverlayController.configuration
// Set the color for the polygons of the tracked barcodes.
configuration.polygonStyle.polygonColor = UIColor(red: 0, green: 0.81, blue: 0.65, alpha: 0.8)
// Set the color for the polygons of the selected tracked barcodes.
configuration.polygonStyle.polygonSelectedColor = UIColor(red:0.784, green:0.1, blue:0.235, alpha:0.8)
// Set the text color of the tracked barcodes.
configuration.textStyle.textColor = UIColor.black
// Set the text background color of the tracked barcodes.
configuration.textStyle.textBackgroundColor = UIColor(red:0, green:0.81, blue:0.65, alpha:0.8)
// Set the text color of the selected tracked barcodes.
configuration.textStyle.selectedTextColor = UIColor.white
// Set the text background color of the selected tracked barcodes.
configuration.textStyle.textBackgroundSelectedColor = UIColor(red:0.784, green:0.1, blue:0.235, alpha:0.8)
// Set the text format of the tracked barcodes.
configuration.textStyle.trackingOverlayTextFormat = .codeAndType
// Set the tracking configuration to apply it.
self.scannerViewController.trackingOverlayController.configuration = configuration
}
}
// The implementation of the SBSDKBarcodeTrackingOverlayControllerDelegate.
extension BarcodesOverlaySwiftViewController: SBSDKBarcodeTrackingOverlayControllerDelegate {
// Implement this method to handle user's selection of a tracked barcode.
func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController,
didTapOnBarcode barcode: SBSDKBarcodeScannerResult) {
// Process the barcode selected by the user.
}
// Implement this method when you need to customize the polygon style individually for every barcode detected.
func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController,
polygonStyleFor barcode: SBSDKBarcodeScannerResult) -> SBSDKBarcodeTrackedViewPolygonStyle? {
let style = SBSDKBarcodeTrackedViewPolygonStyle()
if barcode.type == SBSDKBarcodeType.qrCode {
style.polygonColor = UIColor.red
style.polygonBackgroundColor = UIColor.purple.withAlphaComponent(0.2)
}
return style
}
// Implement this method when you need to customize the text style individually for every barcode detected.
func barcodeTrackingOverlay(_ controller: SBSDKBarcodeTrackingOverlayController,
textStyleFor barcode: SBSDKBarcodeScannerResult) -> SBSDKBarcodeTrackedViewTextStyle? {
let style = SBSDKBarcodeTrackedViewTextStyle()
if barcode.type == SBSDKBarcodeType.qrCode {
style.textBackgroundColor = UIColor.purple.withAlphaComponent(0.2)
}
return style
}
}
#import "BarcodesOverlayObjcViewController.h"
@import ScanbotSDK;
// This is a simple, empty view controller which acts as a container and delegate for the SBSDKBarcodeScannerViewController conforming SBSDKBarcodeTrackingOverlayControllerDelegate.
@interface BarcodesOverlayObjcViewController () <SBSDKBarcodeTrackingOverlayControllerDelegate>
// The instance of the scanner view controller.
@property (strong, nonatomic) SBSDKBarcodeScannerViewController *scannerViewController;
@end
@implementation BarcodesOverlayObjcViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create the SBSDKBarcodeScannerViewController instance.
self.scannerViewController = [[SBSDKBarcodeScannerViewController alloc] initWithParentViewController:self
parentView:self.view];
// Set self as a trackingViewController's delegate.
self.scannerViewController.trackingOverlayController.delegate = self;
// Enable the barcodes tracking overlay.
self.scannerViewController.isTrackingOverlayEnabled = YES;
// Get current tracking configuration object.
SBSDKBarcodeTrackingOverlayConfiguration *configuration =
self.scannerViewController.trackingOverlayController.configuration;
// Set the color for the polygons of the tracked barcodes.
configuration.polygonStyle.polygonColor = [UIColor colorWithRed:0 green:0.81 blue:0.65 alpha:0.8];
// Set the color for the polygons of the selected tracked barcodes.
configuration.polygonStyle.polygonSelectedColor = [UIColor colorWithRed:0.784 green:0.1 blue:0.235 alpha:0.8];
// Set the text color of the tracked barcodes.
configuration.textStyle.textColor = [UIColor blackColor];
// Set the text background color of the tracked barcodes.
configuration.textStyle.textBackgroundColor = [UIColor colorWithRed:0 green:0.81 blue:0.65 alpha:0.8];
// Set the text color of the selected tracked barcodes.
configuration.textStyle.selectedTextColor = [UIColor whiteColor];
// Set the text background color of the selected tracked barcodes.
configuration.textStyle.textBackgroundSelectedColor = [UIColor colorWithRed:0.784 green:0.1 blue:0.235 alpha:0.8];
// Set the text format of the tracked barcodes.
configuration.textStyle.trackingOverlayTextFormat = SBSDKBarcodeOverlayFormatCodeAndType;
// Set the tracking configuration to apply it.
self.scannerViewController.trackingOverlayController.configuration = configuration;
}
// The implementation of the SBSDKBarcodeTrackingOverlayControllerDelegate.
// Implement this method to handle user's selection of a tracked barcode.
- (void)barcodeTrackingOverlay:(SBSDKBarcodeTrackingOverlayController *)controller
didTapOnBarcode:(SBSDKBarcodeScannerResult *)barcode {
// Process the barcode selected by the user.
}
// Implement this method when you need to customize the polygon style individually for every barcode detected.
- (SBSDKBarcodeTrackedViewPolygonStyle *)barcodeTrackingOverlay:(SBSDKBarcodeTrackingOverlayController *)controller
polygonStyleFor:(SBSDKBarcodeScannerResult *)barcode {
SBSDKBarcodeTrackedViewPolygonStyle *style = [[SBSDKBarcodeTrackedViewPolygonStyle alloc] init];
if (barcode.type == [SBSDKBarcodeType qrCode]) {
style.polygonColor = [UIColor redColor];
style.polygonBackgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.2];
}
return style;
}
// Implement this method when you need to customize the text style individually for every barcode detected.
- (SBSDKBarcodeTrackedViewTextStyle *)barcodeTrackingOverlay:(SBSDKBarcodeTrackingOverlayController *)controller
textStyleFor:(SBSDKBarcodeScannerResult *)barcode {
SBSDKBarcodeTrackedViewTextStyle *style = [[SBSDKBarcodeTrackedViewTextStyle alloc] init];
if (barcode.type == [SBSDKBarcodeType qrCode]) {
style.textBackgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.2];
}
return style;
}
@end
Scan and Count
Scan and Count allows you to effortlessly capture 1D and 2D barcodes with a single tap.
You can scan multiple codes per scan, and scan as many times as you want.
The scanner automatically tracks the number of times each code has been detected over multiple scans.
These codes are stored as an array in the countedBarcodes
property.
Example for integrating the Scan and Count Classic UI Component
- Swift
- Objective-C
import Foundation
import ScanbotSDK
// This is a simple, empty view controller which acts as a container and delegate for the SBSDKBarcodeScanAndCountViewController.
class BarcodeScanAndCountSwiftViewController: UIViewController {
// The instance of the scanner view controller.
var scannerViewController: SBSDKBarcodeScanAndCountViewController!
override func viewDidLoad() {
super.viewDidLoad()
// Create the SBSDKBarcodeScanAndCountViewController instance
self.scannerViewController = SBSDKBarcodeScanAndCountViewController(parentViewController: self,
parentView: self.view)
// Create new instance of the polygon style.
let polygonStyle = SBSDKScanAndCountPolygonStyle()
// Enable the barcode polygon overlay.
polygonStyle.polygonDrawingEnabled = true
// Set the color for the results overlays polygons.
polygonStyle.polygonColor = UIColor(red: 0, green: 0.81, blue: 0.65, alpha: 0.8)
// Set the color for the polygon's fill color.
polygonStyle.polygonFillColor = UIColor(red: 0, green: 0.81, blue: 0.65, alpha: 0.2)
// Set the line width for the polygon.
polygonStyle.lineWidth = 2
// Set the corner radius for the polygon.
polygonStyle.cornerRadius = 8
// Set the polygon style to apply it.
self.scannerViewController.polygonStyle = polygonStyle
// Set the capture mode of the scanner.
self.scannerViewController.captureMode = .capturedImage
}
}
// The implementation of SBSDKBarcodeScanAndCountViewControllerDelegate.
extension BarcodeScannerSwiftViewController: SBSDKBarcodeScanAndCountViewControllerDelegate {
// Implement this function to process detected barcodes.
func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController,
didDetectBarcodes codes: [SBSDKBarcodeScannerResult]) {
// Process the detected barcodes.
}
// Implement this optional function when you need a custom overlay to be displayed for the detected barcode.
func barcodeScanAndCount(_ controller: SBSDKBarcodeScanAndCountViewController,
overlayForBarcode code: SBSDKBarcodeScannerResult) -> UIView? {
// provide a custom overlay view for the barcode
return UIImageView(image: UIImage(named: "<image_name>"))
}
}
#import "BarcodeScanAndCountObjcViewController.h"
@import ScanbotSDK;
// This is a simple, empty view controller which acts as a container and delegate for the SBSDKBarcodeScanAndCountViewController.
@interface BarcodeScanAndCountObjcViewController () <SBSDKBarcodeScanAndCountViewControllerDelegate>
// The instance of the scanner view controller.
@property (strong, nonatomic) SBSDKBarcodeScanAndCountViewController *scannerViewController;
@end
@implementation BarcodeScanAndCountObjcViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create the SBSDKBarcodeScanAndCountViewController instance.
self.scannerViewController = [[SBSDKBarcodeScanAndCountViewController alloc] initWithParentViewController:self
parentView:self.view];
// Create new instance of the polygon style.
SBSDKScanAndCountPolygonStyle *polygonStyle = [[SBSDKScanAndCountPolygonStyle alloc] init];
// Enable the barcode polygon overlay.
polygonStyle.polygonDrawingEnabled = YES;
// Set the color for the results overlays polygons.
polygonStyle.polygonColor = [[UIColor alloc] initWithRed:0 green:0.81 blue:0.65 alpha:0.8];
// Set the color for the polygon's fill color.
polygonStyle.polygonFillColor = [[UIColor alloc] initWithRed:0 green:0.81 blue:0.65 alpha:0.2];
// Set the line width for the polygon.
polygonStyle.lineWidth = 2;
// Set the corner radius for the polygon.
polygonStyle.cornerRadius = 8;
// Set the capture mode of the scanner.
self.scannerViewController.captureMode = SBSDKBarcodeScanAndCountCaptureModeCapturedImage;
}
// The implementation of the SBSDKBarcodeScanAndCountViewControllerDelegate.
// Implement this method to process detected barcodes.
- (void)barcodeScanAndCountController:(SBSDKBarcodeScanAndCountViewController *)controller
didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes {
// Process the detected barcodes.
}
// Implement this optional function when you need a custom overlay to be displayed for the detected barcode.
- (UIView *)barcodeScanAndCountController:(SBSDKBarcodeScanAndCountViewController *)controller
overlayForBarcode:(SBSDKBarcodeScannerResult *)code {
// provide a custom overlay view for the barcode
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<image_name>"]];
}
@end
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.