To run the example project, clone the repo, and run pod install
from the Example directory first.
KBStickerView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KBStickerView'
let kbstickerView = KBStickerView()
kbstickerView.translatesAutoresizingMaskIntoConstraints = false
let sitckerPack1: [Sticker] = [
Sticker(data: "ic_recent", resourceType: .assets),
Sticker(data: "ic_sticker", resourceType: .assets)
]
let stickerCategories: [StickerCategory] = [
StickerCategory(stickers: sitckerPack1, icon: "ic_sticker", iconResourceType: .assets)
]
let stickerProvider = StickerProvider(stickerCategories: stickerCategories, stickerDelegate: self, recentsEnabled: true)
kbstickerView.stickerProvider = stickerProvider
//to enable it, set it as an Input View
textView.inputView = kbstickerView
/*
to revert back to normal keyboard
textView.inputView = nil
textView.reloadInputViews()
*/
You are responsible for loading stickers images and Sticker Categories images, you can do that by conforming to Protocols
extension ViewController: StickerProviderDelegate {
func didClickSticker(sticker: Sticker) {
dataSource.append(sticker)
tableView.reloadData()
}
func didChangePage(category: StickerCategory) {
}
func willLoadSticker(imageView: UIImageView, sticker: Sticker) {
if sticker.resourceType == .assets {
let stickerData = sticker.data
let stickerImage = UIImage(named: stickerData)
imageView.image = stickerImage
}
}
func willLoadStickerCategory(imageView: UIImageView, stickerCategory: StickerCategory, selected: Bool) {
if stickerCategory.iconResourceType == .assets {
let icon = stickerCategory.icon
imageView.image = UIImage(named: icon)
}
}
}
it's recommended to do this customizaion Before
kbstickerView.stickerProvider = stickerProvider
kbstickerView.categoriesViewBackground = .red
kbstickerView.selectedCategoryIconBackground = .brown
kbstickerView.categoryIconColorActive = .blue
kbstickerView.categoryIconColorNotActive = .black
kbstickerView.categoryIconSize = CGSize(width: 30, height: 30)
kbstickerView.recentCategoryIcon = "ic_recent"
kbstickerView.recentCategoryResourceType = .assets
kbstickerView.stickerItemSize = CGSize(width: 100, height: 100)
kbstickerView.stickerPageBackground = .black
since willLoadStickerCategory
will be called in your App, you have to have the default icon included ic_recent
in your Assets folder, or just change it to the icon you need.
- Optimize Sample App, especially the UI
- Add a View when there are no Stickers in recents
AbdulAlim Rajjoub
KBStickerView is available under the MIT license. See the LICENSE file for more info.