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:
- In your Xcode project, open File > Add Files to [your project name].
- Navigate to the VPAttributedFormat folder and select the VPAttributedFormat.xcodeproj file.
- Click on the Add button to add VPAttributedFormat to your project.
- In the Project Navigator, select your project’s target.
- In the General tab, scroll down to Embedded Binaries.
- Click on the + button.
- Choose the VPAttributedFormat.framework file and click on the Add button.
- VPAttributedFormat should now appear under the Embedded Binaries section.
Usage
To use VPAttributedFormat in your app, follow these steps:
- Import the VPAttributedFormat framework into your view controller:
- Create an instance of the VPAttributedFormat class:
- Apply formatting to your string using the available methods:
- Use the resulting NSAttributedString object as needed.
// Swiftimport VPAttributedFormat
// Objective-C@import VPAttributedFormat;
// Swiftlet attributedFormat = VPAttributedFormat()
// Objective-CVPAttributedFormat *attributedFormat = [[VPAttributedFormat alloc] init];
// Swiftlet formattedString = attributedFormat.string("Hello, World!") .withTextColor(.red) .withFont(UIFont.systemFont(ofSize: 20)) .applyFormatting()
// Objective-CNSAttributedString *formattedString = [[attributedFormat string:@"Hello, World!"] withTextColor:[UIColor redColor]] .withFont:[UIFont systemFontOfSize:20]] .applyFormatting];
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.