VPAttributedFormat

About VPAttributedFormat

VPAttributedFormat is a powerful library that allows you to easily format attributed strings in your iOS app. With its intuitive API, you can apply various formatting options to your strings, such as changing text color, font size, and more. Built specifically for Objective-C, this library ensures efficient and convenient string formatting.

Features

  • Effortlessly format attributed strings
  • Apply various styling options
  • Change text color, font size, and more with ease
  • Compatible with Objective-C
  • Intuitive and simple API

Installation

To integrate VPAttributedFormat into your project, follow these steps:

  1. In your Xcode project, open File > Add Files to [your project name].
  2. Navigate to the VPAttributedFormat folder and select the VPAttributedFormat.xcodeproj file.
  3. Click on the Add button to add VPAttributedFormat to your project.
  4. In the Project Navigator, select your project’s target.
  5. In the General tab, scroll down to Embedded Binaries.
  6. Click on the + button.
  7. Choose the VPAttributedFormat.framework file and click on the Add button.
  8. VPAttributedFormat should now appear under the Embedded Binaries section.

Usage

To use VPAttributedFormat in your app, follow these steps:

  1. Import the VPAttributedFormat framework into your view controller:
  2. // Swift
    import VPAttributedFormat
    
    // Objective-C
    @import VPAttributedFormat;
  3. Create an instance of the VPAttributedFormat class:
  4. // Swift
    let attributedFormat = VPAttributedFormat()
    
    // Objective-C
    VPAttributedFormat *attributedFormat = [[VPAttributedFormat alloc] init];
  5. Apply formatting to your string using the available methods:
  6. // Swift
    let formattedString = attributedFormat.string("Hello, World!")
                                     .withTextColor(.red)
                                     .withFont(UIFont.systemFont(ofSize: 20))
                                     .applyFormatting()
    
    // Objective-C
    NSAttributedString *formattedString = [[attributedFormat string:@"Hello, World!"]
                                               withTextColor:[UIColor redColor]]
                                              .withFont:[UIFont systemFontOfSize:20]]
                                              .applyFormatting];
  7. Use the resulting NSAttributedString object as needed.

API Reference

VPAttributedFormat provides the following methods to format your attributed strings:

  • string(_: String): Sets the initial string to be formatted.
  • withTextColor(_: UIColor): Sets the text color of the attributed string.
  • withFont(_: UIFont): Sets the font of the attributed string.
  • withUnderline(): Adds an underline attribute to the attributed string.
  • withStrikethrough(): Adds a strikethrough attribute to the attributed string.
  • withBackgroundColor(_: UIColor): Sets the background color of the attributed string.
  • withAlignment(_: NSTextAlignment): Sets the text alignment of the attributed string.
  • applyFormatting(): Applies the formatting options and returns the resulting attributed string.

Example

Here’s an example of how you can apply formatting using VPAttributedFormat:

import VPAttributedFormat

// ...

let attributedFormat = VPAttributedFormat()

let formattedString = attributedFormat.string("Welcome to my app!")
                                     .withTextColor(.blue)
                                     .withBackgroundColor(.yellow)
                                     .withFont(UIFont.boldSystemFont(ofSize: 18))
                                     .withUnderline()
                                     .applyFormatting()

Requirements

  • iOS 9.0 or later
  • Objective-C

License

VPAttributedFormat is available under the MIT license. See the LICENSE file for more info.