Introduction
GBFlatButton is a customizable button subclass for iOS built with Charts framework.
Features
1. Customization
GBFlatButton offers extensive customization options, allowing you to easily change the appearance and behavior of your buttons to fit your app’s design.
2. Easy Integration
With its simple implementation, GBFlatButton can be easily integrated into your project without any hassle.
3. Compatible with Charts Framework
By leveraging the power of the popular Charts framework, GBFlatButton enables you to create stylish buttons that can be integrated seamlessly with your app’s chart components.
4. Accessibility Support
GBFlatButton is designed with accessibility in mind, ensuring that all users, including those with disabilities, can easily interact with your app’s buttons.
Installation
- Add the following pod to your
Podfile
:// Podfile pod 'GBFlatButton'
- Run the following command in the Terminal:
$ pod install
- Import GBFlatButton in the relevant source file:
// Swift import GBFlatButton // Objective-C @import GBFlatButton;
Usage
To create a GBFlatButton, simply initialize it with the desired frame and customize its properties as needed.
- Create an instance of GBFlatButton:
// Swift let flatButton = GBFlatButton(frame: CGRect(x: 0, y: 0, width: 120, height: 40)) // Objective-C GBFlatButton *flatButton = [[GBFlatButton alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
- Customize the button properties:
flatButton.buttonColor = .blue flatButton.titleColor = .white flatButton.cornerRadius = 8
- Add the button to your view:
self.view.addSubview(flatButton)
Example
Let’s create an example that demonstrates the usage of GBFlatButton in a simple login screen:
// Swift
let loginButton = GBFlatButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
loginButton.buttonColor = .systemBlue
loginButton.titleColor = .white
loginButton.cornerRadius = 5
loginButton.setTitle("Login", for: .normal)
loginButton.addTarget(self, action: #selector(loginButtonTapped), for: .touchUpInside)
self.view.addSubview(loginButton)
// Objective-C
GBFlatButton *loginButton = [[GBFlatButton alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
loginButton.buttonColor = UIColor.systemBlueColor;
loginButton.titleColor = UIColor.whiteColor;
loginButton.cornerRadius = 5;
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
[loginButton addTarget:self action:@selector(loginButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:loginButton];
Conclusion
GBFlatButton is a powerful tool for creating highly customizable iOS buttons that seamlessly integrate with the Charts framework. Its easy integration and extensive customization options make it a great choice for adding stylish buttons to your app.