Skip to content

Commit

Permalink
create bundle extension
Browse files Browse the repository at this point in the history
  • Loading branch information
huangminlinux committed May 4, 2017
1 parent 90a60e1 commit 0fbdab1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
15 changes: 15 additions & 0 deletions iOS/IMUI/Extension/BundleExtension.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 3 additions & 1 deletion iOS/IMUI/Extension/UIImageExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions iOS/IMUI/Views/IMUIInputView/Views/IMUIFeatureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions iOS/IMUI/Views/IMUIMessageCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions iOS/IMUIChat/IMUIChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -83,6 +84,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
622271851EBB5B030062402B /* BundleExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BundleExtension.swift; sourceTree = "<group>"; };
622532181EA0C8A400F6927E /* IMUIMessageCellProtocal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IMUIMessageCellProtocal.swift; sourceTree = "<group>"; };
6225321B1EA0D42400F6927E /* IMUIInputView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IMUIInputView.swift; sourceTree = "<group>"; };
6225321C1EA0D42400F6927E /* IMUIInputView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IMUIInputView.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -290,6 +292,7 @@
62C869C01E9B51AE00AA8FE9 /* UIColorExtension.swift */,
62C869C11E9B51AE00AA8FE9 /* UIImageExtension.swift */,
62C869C21E9B51AE00AA8FE9 /* UIViewExtension.swift */,
622271851EBB5B030062402B /* BundleExtension.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 0fbdab1

Please sign in to comment.