Introduction
dlradiobutton is a lightweight and customizable radio button component for iOS, written in Objective-C. It provides a simple way to incorporate radio buttons in your iOS applications.
Features
- Elegant and customizable UI
- Supports both single and multiple selection mode
- Easy integration with any iOS project
- Works well with both Objective-C and Swift codebases
- Lightweight implementation with minimal code overhead
Requirements
- iOS 9.0+
- Xcode 9.0+
- Objective-C or Swift codebase
Installation
CocoaPods
To integrate dlradiobutton into your Xcode project using CocoaPods, add the following line to your Podfile:
pod 'dlradiobutton', '~> 1.0'
Then, run the following command:
$ pod install
Manual Installation
- Download the latest version of dlradiobutton.
- Copy the
DLRadioButton
folder to your Xcode project. - Make sure to select “Copy items if needed” when prompted.
Usage
Objective-C Example
Import the dlradiobutton header in your ViewController:
#import "DLRadioButton.h"
Create an instance of DLRadioButton and configure its properties:
DLRadioButton *radioButton1 = [[DLRadioButton alloc] initWithFrame:CGRectMake(50, 50, 150, 30)];
radioButton1.titleLabel.font = [UIFont systemFontOfSize:14];
[radioButton1 setTitle:@"Option 1" forState:UIControlStateNormal];
radioButton1.icon = [UIImage imageNamed:@"unchecked_icon"];
radioButton1.iconSelected = [UIImage imageNamed:@"checked_icon"];
radioButton1.iconSize = 20;
radioButton1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[radioButton1 addTarget:self action:@selector(radioButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
Add the radio button to your view hierarchy:
[self.view addSubview:radioButton1];
Swift Example
Import the dlradiobutton module in your ViewController:
import DLRadioButton
Create an instance of DLRadioButton and configure its properties:
let radioButton1 = DLRadioButton(frame: CGRect(x: 50, y: 50, width: 150, height: 30))
radioButton1.titleLabel?.font = UIFont.systemFont(ofSize: 14)
radioButton1.setTitle("Option 1", for: .normal)
radioButton1.icon = UIImage(named: "unchecked_icon")
radioButton1.iconSelected = UIImage(named: "checked_icon")
radioButton1.iconSize = 20
radioButton1.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
radioButton1.addTarget(self, action: #selector(radioButtonSelected(_:)), for: .touchUpInside)
Add the radio button to your view hierarchy:
self.view.addSubview(radioButton1)
Delegation
To respond to changes in radio button selection, implement the radioButtonSelected:
method:
- (void)radioButtonSelected:(DLRadioButton *)radioButton {
NSLog(@"Selected radio button: %@", radioButton.titleLabel.text);
}
Customization
DLRadioButton allows customization of various properties:
icon
: The icon displayed when the radio button is not selectediconSelected
: The icon displayed when the radio button is selectediconSize
: The size of the radio button iconcontentHorizontalAlignment
: The alignment of the radio button content (e.g., left, center, right)titleLabel
: The label displaying the radio button title
Contributing
If you encounter any issues or have suggestions for improvements, please feel free to contribute. You can fork this repository, make your changes, and submit a pull request. Contributions are highly appreciated!
License
dlradiobutton is released under the MIT License. See the LICENSE file for more information.