diff --git a/Demo/DemoListViewController.swift b/Demo/DemoListViewController.swift index bc8f06e..3c6638f 100644 --- a/Demo/DemoListViewController.swift +++ b/Demo/DemoListViewController.swift @@ -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) { diff --git a/NohanaImagePicker/AlbumListEmptyIndicator.swift b/NohanaImagePicker/AlbumListEmptyIndicator.swift index 085b1ec..5db4d3f 100644 --- a/NohanaImagePicker/AlbumListEmptyIndicator.swift +++ b/NohanaImagePicker/AlbumListEmptyIndicator.swift @@ -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 ] diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index 1ebf67f..35db63b 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -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 diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index b8fb615..d9d9a5d 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -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 { diff --git a/NohanaImagePicker/MomentCell.swift b/NohanaImagePicker/MomentCell.swift index 7f5208d..55926fc 100644 --- a/NohanaImagePicker/MomentCell.swift +++ b/NohanaImagePicker/MomentCell.swift @@ -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)) } diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index ee7ea18..d777016 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -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() } - }