From 0fbdab1e11760f7ecec49dfa2eded04e03c6636e Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 4 May 2017 20:55:16 +0800 Subject: [PATCH] create bundle extension --- iOS/IMUI/Extension/BundleExtension.swift | 15 +++++++++++++++ iOS/IMUI/Extension/UIImageExtension.swift | 4 +++- .../IMUIInputView/Controllers/IMUIInputView.swift | 2 +- .../IMUIInputView/Views/IMUIFeatureView.swift | 11 +++++++---- iOS/IMUI/Views/IMUIMessageCollectionView.swift | 4 ++-- iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj | 4 ++++ 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 iOS/IMUI/Extension/BundleExtension.swift diff --git a/iOS/IMUI/Extension/BundleExtension.swift b/iOS/IMUI/Extension/BundleExtension.swift new file mode 100644 index 00000000..7a44d68b --- /dev/null +++ b/iOS/IMUI/Extension/BundleExtension.swift @@ -0,0 +1,15 @@ +// +// BundleExtension.swift +// IMUIChat +// +// Created by oshumini on 2017/5/4. +// Copyright © 2017年 HXHG. All rights reserved. +// + +import Foundation + +public extension Bundle { + class func imuiBundle() -> Bundle { + return Bundle(for: IMUIMessageCollectionView.self) + } +} diff --git a/iOS/IMUI/Extension/UIImageExtension.swift b/iOS/IMUI/Extension/UIImageExtension.swift index 87034838..5bbe0b76 100644 --- a/iOS/IMUI/Extension/UIImageExtension.swift +++ b/iOS/IMUI/Extension/UIImageExtension.swift @@ -11,7 +11,9 @@ import UIKit public extension UIImage { class func imuiImage(with name: String) -> UIImage? { - return UIImage(named: "IMUIAssets.bundle/image/\(name).png") + let bundle = Bundle.imuiBundle() + let imagePath = bundle.path(forResource: "IMUIAssets.bundle/image/\(name)", ofType: "png") + return UIImage(contentsOfFile: imagePath!) } var jpegRepresentationData: Data! { diff --git a/iOS/IMUI/Views/IMUIInputView/Controllers/IMUIInputView.swift b/iOS/IMUI/Views/IMUIInputView/Controllers/IMUIInputView.swift index 49fd881d..efa62602 100644 --- a/iOS/IMUI/Views/IMUIInputView/Controllers/IMUIInputView.swift +++ b/iOS/IMUI/Views/IMUIInputView/Controllers/IMUIInputView.swift @@ -62,7 +62,7 @@ open class IMUIInputView: UIView { // view = Bundle.main.loadNibNamed("IMUIInputView", owner: self, options: nil)?[0] as! UIView - let bundle = Bundle(for: IMUIInputView.self) + let bundle = Bundle.imuiBundle() view = bundle.loadNibNamed("IMUIInputView", owner: self, options: nil)?.first as! UIView self.addSubview(view) diff --git a/iOS/IMUI/Views/IMUIInputView/Views/IMUIFeatureView.swift b/iOS/IMUI/Views/IMUIInputView/Views/IMUIFeatureView.swift index 571cb9c7..7c8f9d22 100644 --- a/iOS/IMUI/Views/IMUIInputView/Views/IMUIFeatureView.swift +++ b/iOS/IMUI/Views/IMUIInputView/Views/IMUIFeatureView.swift @@ -73,7 +73,7 @@ open class IMUIFeatureView: UIView { super.init(coder: aDecoder) // view = Bundle.main.loadNibNamed("IMUIFeatureView", owner: self, options: nil)?[0] as! UIView - let bundle = Bundle(for: IMUIFeatureView.self) + let bundle = Bundle.imuiBundle() view = bundle.loadNibNamed("IMUIFeatureView", owner: self, options: nil)?.first as! UIView self.addSubview(view) @@ -82,9 +82,12 @@ open class IMUIFeatureView: UIView { func setupAllViews() { - self.featureCollectionView.register(UINib(nibName: "IMUIRecordVoiceCell", bundle: nil), forCellWithReuseIdentifier: "IMUIRecordVoiceCell") - self.featureCollectionView.register(UINib(nibName: "IMUIGalleryCell", bundle: nil), forCellWithReuseIdentifier: "IMUIGalleryCell") - self.featureCollectionView.register(UINib(nibName: "IMUICameraCell", bundle: nil), forCellWithReuseIdentifier: "IMUICameraCell") + let bundle = Bundle.imuiBundle() + + self.featureCollectionView.register(UINib(nibName: "IMUIRecordVoiceCell", bundle: bundle), forCellWithReuseIdentifier: "IMUIRecordVoiceCell") + self.featureCollectionView.register(UINib(nibName: "IMUIGalleryCell", bundle: bundle), forCellWithReuseIdentifier: "IMUIGalleryCell") + self.featureCollectionView.register(UINib(nibName: "IMUICameraCell", bundle: bundle), forCellWithReuseIdentifier: "IMUICameraCell") + self.featureCollectionView.delegate = self self.featureCollectionView.dataSource = self diff --git a/iOS/IMUI/Views/IMUIMessageCollectionView.swift b/iOS/IMUI/Views/IMUIMessageCollectionView.swift index 56fec3cc..e7551766 100644 --- a/iOS/IMUI/Views/IMUIMessageCollectionView.swift +++ b/iOS/IMUI/Views/IMUIMessageCollectionView.swift @@ -15,7 +15,7 @@ open class IMUIMessageCollectionView: UIView { @IBOutlet weak var messageCollectionView: UICollectionView! var chatDataManager = IMUIChatDataManager() - weak var delegate: IMUIMessageMessageCollectionViewDelegate? + open weak var delegate: IMUIMessageMessageCollectionViewDelegate? open override func awakeFromNib() { super.awakeFromNib() @@ -25,7 +25,7 @@ open class IMUIMessageCollectionView: UIView { required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - let bundle = Bundle(for: IMUIMessageCollectionView.self) + let bundle = Bundle.imuiBundle() view = bundle.loadNibNamed("IMUIMessageCollectionView", owner: self, options: nil)?.first as! UIView self.addSubview(view) diff --git a/iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj b/iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj index cf70ffc3..4d9caebd 100644 --- a/iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj +++ b/iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 622271861EBB5B030062402B /* BundleExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 622271851EBB5B030062402B /* BundleExtension.swift */; }; 622532191EA0C8A400F6927E /* IMUIMessageCellProtocal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 622532181EA0C8A400F6927E /* IMUIMessageCellProtocal.swift */; }; 6225321D1EA0D42400F6927E /* IMUIInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6225321B1EA0D42400F6927E /* IMUIInputView.swift */; }; 6225321E1EA0D42400F6927E /* IMUIInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6225321C1EA0D42400F6927E /* IMUIInputView.xib */; }; @@ -83,6 +84,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 622271851EBB5B030062402B /* BundleExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BundleExtension.swift; sourceTree = ""; }; 622532181EA0C8A400F6927E /* IMUIMessageCellProtocal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IMUIMessageCellProtocal.swift; sourceTree = ""; }; 6225321B1EA0D42400F6927E /* IMUIInputView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IMUIInputView.swift; sourceTree = ""; }; 6225321C1EA0D42400F6927E /* IMUIInputView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IMUIInputView.xib; sourceTree = ""; }; @@ -290,6 +292,7 @@ 62C869C01E9B51AE00AA8FE9 /* UIColorExtension.swift */, 62C869C11E9B51AE00AA8FE9 /* UIImageExtension.swift */, 62C869C21E9B51AE00AA8FE9 /* UIViewExtension.swift */, + 622271851EBB5B030062402B /* BundleExtension.swift */, ); path = Extension; sourceTree = ""; @@ -553,6 +556,7 @@ 622532201EA0D45C00F6927E /* IMUIInputViewDelegate.swift in Sources */, 62C86A211E9B568F00AA8FE9 /* IMUICameraCell.swift in Sources */, 62C86A111E9B564800AA8FE9 /* IMUIGalleryDataManager.swift in Sources */, + 622271861EBB5B030062402B /* BundleExtension.swift in Sources */, 62C869E51E9B51AE00AA8FE9 /* IMUIAudioPlayerHelper.swift in Sources */, 62C869F41E9B51AE00AA8FE9 /* IMUIMessageModel.swift in Sources */, 62C869F61E9B51AE00AA8FE9 /* IMUIMessageModelProtocol.swift in Sources */,