Merge pull request #79 from nohana/feature/config-for-custom-strings
config color, image, strings
This commit is contained in:
commit
8846e8c28d
|
|
@ -130,11 +130,14 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
|||
func showCustomUIPicker() {
|
||||
let picker = NohanaImagePickerController()
|
||||
picker.delegate = self
|
||||
picker.config.color.background = .lightGray
|
||||
picker.config.color.background = UIColor(red: 0xcc/0xff, green: 0xff/0xff, blue: 0xff/0xff, alpha: 1)
|
||||
picker.config.color.separator = UIColor(red: 0x00/0xff, green: 0x66/0xff, blue: 0x66/0xff, alpha: 1)
|
||||
picker.config.strings.albumListTitle = "🏞"
|
||||
picker.config.image.droppedSmall = UIImage(named: "btn_select_m")
|
||||
picker.config.image.pickedSmall = UIImage(named: "btn_selected_m")
|
||||
present(picker, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NohanaImagePickerControllerDelegate
|
||||
|
||||
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ class AlbumListEmptyIndicator: UILabel {
|
|||
centerStyle.alignment = NSTextAlignment.center
|
||||
|
||||
let messageAttributes = [
|
||||
NSForegroundColorAttributeName : config.color.empty,
|
||||
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
||||
NSFontAttributeName : UIFont.systemFont(ofSize: 26),
|
||||
NSParagraphStyleAttributeName : centerStyle
|
||||
]
|
||||
let messageText = NSAttributedString(string: message, attributes: messageAttributes)
|
||||
|
||||
let descriptionAttributes = [
|
||||
NSForegroundColorAttributeName : config.color.empty,
|
||||
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
||||
NSFontAttributeName : UIFont.systemFont(ofSize: 14),
|
||||
NSParagraphStyleAttributeName : centerStyle
|
||||
]
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||
title = NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||
view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white
|
||||
title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||
setUpToolbarItems()
|
||||
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden ,animated: false)
|
||||
}
|
||||
setUpEmptyIndicator()
|
||||
setUpActivityIndicator()
|
||||
self.view.backgroundColor = nohanaImagePickerController?.config.color.background
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
|
@ -140,7 +140,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
|||
}
|
||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||
cell.config = nohanaImagePickerController.config
|
||||
cell.titleLabel?.text = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||
cell.titleLabel?.text = nohanaImagePickerController.config.strings.albumListMomentTitle ?? NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||
}
|
||||
return cell
|
||||
case .albums:
|
||||
|
|
@ -221,8 +221,8 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
|||
return
|
||||
}
|
||||
emptyIndicator = AlbumListEmptyIndicator(
|
||||
message: NSLocalizedString("albumlist.empty.message", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
description: NSLocalizedString("albumlist.empty.description", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
message: nohanaImagePickerController.config.strings.albumListEmptyMessage ?? NSLocalizedString("albumlist.empty.message", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
description: nohanaImagePickerController.config.strings.albumListEmptyDescription ?? NSLocalizedString("albumlist.empty.description", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
frame: frame,
|
||||
config: nohanaImagePickerController.config)
|
||||
}
|
||||
|
|
@ -274,11 +274,11 @@ extension UIViewController {
|
|||
return
|
||||
}
|
||||
if nohanaImagePickerController.maximumNumberOfSelection == 0 {
|
||||
let title = String(format: NSLocalizedString("toolbar.title.nolimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleNoLimit ?? NSLocalizedString("toolbar.title.nolimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
nohanaImagePickerController.pickedAssetList.count)
|
||||
infoButton.title = title
|
||||
} else {
|
||||
let title = String(format: NSLocalizedString("toolbar.title.haslimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
let title = String(format: nohanaImagePickerController.config.strings.toolbarTitleHasLimit ?? NSLocalizedString("toolbar.title.haslimit", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: ""),
|
||||
nohanaImagePickerController.pickedAssetList.count,
|
||||
nohanaImagePickerController.maximumNumberOfSelection)
|
||||
infoButton.title = title
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ class AssetListViewController: UICollectionViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white
|
||||
updateTitle()
|
||||
setUpToolbarItems()
|
||||
addPickPhotoKitAssetNotificationObservers()
|
||||
self.view.backgroundColor = nohanaImagePickerController?.config.color.background
|
||||
}
|
||||
|
||||
var cellSize: CGSize {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class MomentCell: AlbumCell {
|
|||
override func draw(_ rect: CGRect) {
|
||||
super.draw(rect)
|
||||
let lineWidth: CGFloat = 1 / UIScreen.main.scale
|
||||
config.color.separator.setFill()
|
||||
let separatorColor: UIColor = config.color.separator ?? UIColor(red: 0xbb/0xff, green: 0xbb/0xff, blue: 0xbb/0xff, alpha: 1)
|
||||
separatorColor.setFill()
|
||||
UIRectFill(CGRect(x: 16, y: frame.size.height - lineWidth, width: frame.size.width, height:lineWidth))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,11 +141,11 @@ open class NohanaImagePickerController: UIViewController {
|
|||
extension NohanaImagePickerController {
|
||||
public struct Config {
|
||||
public struct Color {
|
||||
public var background: UIColor = .white
|
||||
public var empty: UIColor = UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1)
|
||||
public var separator: UIColor = UIColor(red: 0xbb/0xff, green: 0xbb/0xff, blue: 0xbb/0xff, alpha: 1)
|
||||
public var background: UIColor?
|
||||
public var empty: UIColor?
|
||||
public var separator: UIColor?
|
||||
}
|
||||
public var color: Color = Color()
|
||||
public var color = Color()
|
||||
|
||||
public struct Image {
|
||||
public var pickedSmall: UIImage?
|
||||
|
|
@ -153,7 +153,16 @@ extension NohanaImagePickerController {
|
|||
public var droppedSmall: UIImage?
|
||||
public var droppedLarge: UIImage?
|
||||
}
|
||||
public var image: Image = Image()
|
||||
public var image = Image()
|
||||
|
||||
public struct Strings {
|
||||
public var albumListTitle: String?
|
||||
public var albumListMomentTitle: String?
|
||||
public var albumListEmptyMessage: String?
|
||||
public var albumListEmptyDescription: String?
|
||||
public var toolbarTitleNoLimit: String?
|
||||
public var toolbarTitleHasLimit: String?
|
||||
}
|
||||
public var strings = Strings()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue