TNCheckboxGroup
Last year I published TNCheckboxGroup for Objective-C, but I had a few comments it didn’t work when using with Swift. So I just published a Swift version on Github. This versions leverages UICollectionView to handle big sets of checkboxes. TNSwiftyCheckboxGroup, create checkbox groups in Swift.
Introducing TNSwiftyCheckboxGroup – checkbox groups in Swift
All the details about implementing the view controller are explained in the README of the Github project. There is an example project which shows you the different options.
Prerequisites
- Xcode
- iOS8+
- Swift project
Features
- 3 predefined styles (checkbox, radio button, image)
- Possibility to add your own checkbox styles
- Delegate object to get informed when your checkbox group changes
- Storyboards & programmatic approach
- Works in both orientations (landscape / portrait)
- AutoLayout behind the scenes
Options
There are quite a few ways to customize the existing styles. Here is a brief overview:
- CollectionViewWidthOfCell : The width of the checkbox cell. Default: 150
- CollectionViewBackgroundColor : The background color of the collection view. Default: White
- FontOfNameLabel : The font of the name label. Default: System 12pt
- FontColorOfNameLabel : The font color of the name label. Default: #333333
- PreferredWidthOfNameLabel : The preferred width for the name label. Default: 100
- CheckboxOuterColor : The outer color for the built-in checkbox types. Default: #333333
- CheckboxInnerColor : The outer color for the built-in checkbox types. Default: White
- CheckboxPadding : The padding between the inner and outer views of the build-in checkbox types. Default: 5
- CheckboxUncheckedImageName : The image name for the unchecked image (defined in your image assets catalog), if you are using the
TNSwiftyImageCheckboxView
style. Default: unchecked-image - CheckboxCheckedImageName : The image name for the checked image (defined in your image assets catalog), if you are using the
TNSwiftyImageCheckboxView
style. Default: checked-image
To use these options, you just have to implement the style datasource method.
func styleDictionaryForCheckboxView() -> [String : AnyObject] {
return [
TNSwiftyCheckboxStyleOptions.CheckboxOuterColor : UIColor.redColor(),
]
}
SwiftI hope you will like it. If you have any requests, please post them via the comments below or add an issue on Github.
5 Responses
This is a great library. I really like it and would like to use it in my application. However, it does not work with Swift 2.0 :-(.
Since I am a newbie, it took me 2 days already and still could not figure out the “Optional” issues in TNSwiftyCheckboxCustomLayout.swift. It is probably a simple issue. Anyone has time to look at it?
Thanks for mentioning it doesn’t work on Swift 2. I’ll investigate the problem this afternoon and put the solution in a seperate Swift 2.0 branch on GitHub!
I have updated the library with a new Swift_2 branch on GitHub. You can check it out here https://github.com/frederik-jacques/TNSwiftyCheckboxGroup/tree/swift_2
This fixes the issues, you’ll see a warning in the console “This is likely occurring because the flow layout subclass TNSwiftyCheckboxGroup.TNSwiftyCheckboxCustomLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them”, but you can ignore it as I do copy the attributes. Don’t know why it is complaining (maybe it is still a bug in Xcode 7 Beta)
Any chance of you upgrading it to Swift 3 ??