TextStyle class
TextStyle class consists of following parameters. Required parameters must be set at initialisation.
Parameters Required
Required| Parameter | Type | Description |
|---|---|---|
| text | String | String text |
let textStyle = TextStyle(text: "Cancel payment")Parameters Optional
Optional| Parameter | Type | Description |
|---|---|---|
| color | String | HEX value color of text |
| font | UIFont | Text font |
| size | CGFloat? | Text font size |
| weight | UIFont.Weight? | Text font weight |
Example
var buttonStyle = ButtonStyle(type: .text)
// Default font example:
var textStyle = TextStyle(text: "Close payment", size: 15, weight: .semibold)
// Custom font example:
// var textStyle = TextStyle(text: "Close payment", fontName: "Arial-Bold", size: 15)
textStyle.color = "0476BA"
buttonStyle.textStyle = textStyleAdding a Custom Font to your iOS app
Apple - Adding a Custom Font to Your App
Example
guard let customFont = UIFont(name: "CustomFont-Light", size: UIFont.labelFontSize) else {
fatalError("""
Failed to load the "CustomFont-Light" font.
Make sure the font file is included in the project and the font name is spelled correctly.
"""
)
}
var buttonStyle = ButtonStyle(type: .text)
var textStyle = TextStyle(text: "Close payment", font: customFont)
textStyle.color = "0476BA"
buttonStyle.textStyle = textStyleUpdated 8 months ago
