FUIFormattedStringEditing
public protocol FUIFormattedStringEditing : AnyObject
This is the formatter protocol to handle special formatting of the text used in the UITextField
of FUITextFieldFormCell
.
Currently, SAPFiori provides two implementations:
FUIPhoneNumberFormatter
to format phone numbers.FUINumberFormatter
to format numbers that uses the regular iOSNumberFormatter
.
-
This function formats the specified string with the specified cursor position then returns the formatted
NSAttributedStering
and the adjusted cursor position.The implementation may return nil for this function. In that case, the caller should expect to use the other function to format the string:
func string(for string: String, cursorPosition: Int) -> (formattedString: String?, adjustedCursorPosition: Int)?
Declaration
Swift
func attributedString(for string: String, withDefaultAttributes attrs: [NSAttributedString.Key : Any]?, cursorPosition: Int) -> (formattedAttributedString: NSAttributedString?, adjustedCursorPosition: Int)?
Parameters
string
The original string to be formatted.
attrs
The default attributes for the formatted
NSAttributedString
.cursorPosition
The cursor position of a
UITextField
or other similar UI components.Return Value
A tupple containing the
NSAttributedString
after format, and the adjusted cursor position. -
This function formats the specified string with the specified cursor position then returns the formatted string and the adjusted cursor position.
Declaration
Swift
func string(for string: String, cursorPosition: Int) -> (formattedString: String?, adjustedCursorPosition: Int)?
Parameters
string
The original string to be formatted.
cursorPosition
The cursor position of a
UITextField
or other similar UI components.Return Value
A tupple containing the string after format, and the adjusted cursor position.
-
This function returns the string user typped from formatted string.
This function is similar to the function with the same signature as in the standard iOS SDK
Formatter
.Declaration
Swift
func editingString(for obj: Any) -> String?
Parameters
obj
The implementation should expect this to be a
String
, representing the formatted string.Return Value
The original string without format.
-
This function checks if the given
partialString
is acceptable to the formatter or not.This function is similar to the function with the same signature as in the standard iOS SDK
Formatter
.Declaration
Swift
func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool
Parameters
partialString
The string that is to be added to the editing string.
newEditingString
The current editing string.
error
This parameter is not used.
Return Value
true
if thepartialString
is to be accepted.