Samples
VGS Show iOS SDK Samples
Check samples and code examples how to use VGS Show SDK features.
Text Formatting in VGSLabel
You have an option to transform the revealed text with specified pattern in addTransformationRegex(_:)
function.
Code example
/// Option 1. Card Number formatting
// Create regex object, split card number to XXXX XXXX XXXX XXXX format.
let cardNumberPattern = "(\\d{4})(\\d{4})(\\d{4})(\\d{4})"
let template = "$1 $2 $3 $4"
// Use force try! here for sample.
let regex = try! NSRegularExpression(pattern: cardNumberPattern, options: [])
// Add transformation regex and template to your label.
cardNumberLabel.addTransformationRegex(regex, template: template)
/// Option 2. Social Security Number formatting
// Create regex object, split SSN to XXX-XX-XXXX format.
let ssnPattern = "(\\d{3})(\\d{2})(\\d{4})"
let template = "$1 $2 $3"
// Use force try! here for sample.
let regex = try! NSRegularExpression(pattern: ssnPattern, options: [])
// Add transformation regex and template to your label.
ssnLabel.addTransformationRegex(regex, template: template)
Secure text in VGSLabel
You can hide revealed text with secureTextSymbol
fully or partially. Check the code examples how to add an option for your users to show/hide revealed data.
Code example
// Revealed Data
4111111111111111
// Displayed string in VGSLabel after modification with transformation regex
4111-1111-1111-1111
// Option 1. Secure all text in VGSLabel
label.isSecureText = true // => "*******************"
// Option 2. Change secure symbol
label.secureTextSymbol = "x" // => "xxxxxxxxxxxxxxxxxxx"
// Option 3. Secure text from 4th character
label.setSecureText(start: 4) // => "4111xxxxxxxxxxxxxxx"
// Option 4. Secure text till 15th character
label.setSecureText(end: 14) // => "xxxxxxxxxxxxxxx1111"
// Option 5. Secure text from 4th till 14th characters
label.setSecureText(start: 4, end: 14) // => "4111xxxxxxxxxxx1111"
// Option 6. Secure text in ranges [5,8] & [10, 13]
let range1 = VGSTextRange(start: 5, end: 8)
let range2 = VGSTextRange(start: 10, end: 13)
label.setSecureText(ranges: [range1, range2]) // => "4111-xxxx-xxxx-1111"
Last updated