先上一张演示图片,最终就是这样的效果。Swift的小伙伴是如何集成这个界面呢?
首先将Demo中的CLPhotoView文件夹直接拖入你的工程,切记要勾选Copy items if needed。
然后在桥文件中import
#import "CLTextView.h"
#import "CLPhotosVIew.h"
#import "TZImagePickerController.h"
最后在你的ViewController中调用就可以了
import UIKit
class ViewController: UIViewController,UITextViewDelegate {
var phontView:CLPhotosVIew!
var imgArr:NSMutableArray!
/*懒加载*/
func ImgArr() -> NSMutableArray {
if imgArr == nil {
self.imgArr = NSMutableArray()
}
return imgArr
}
override func viewDidLoad() {
super.viewDidLoad()
/*创建一个输入框*/
let width = self.view.frame.size.width
let textView = CLTextView(frame: CGRectMake(0, 64, width, 300))
textView.backgroundColor = UIColor.whiteColor()
textView.delegate = self
textView.placehoder = "请输入要评论的内容..."
self.view.addSubview(textView)
/*创建一个添加图片View*/
let photosView = CLPhotosVIew(frame: CGRectMake(10,50,textView.frame.size.width-20,250))
self.phontView = photosView
photosView.photoArray = [UIImage(named: "images_01")!]
var weakSelf = ViewController()
weakSelf = self
photosView.clickcloseImage = {(index:NSInteger) -> Void in
weakSelf.ImgArr().removeObjectAtIndex(index)
}
/*点击添加图片View打开选择图片界面*/
photosView.clickChooseView = {
let imagePickerVc = TZImagePickerController(maxImagesCount: 9, delegate: nil)
imagePickerVc.didFinishPickingPhotosHandle = {(photos:[UIImage]!,assets:[AnyObject]!,isSelectOriginalPhoto:Bool) -> Void in
weakSelf.ImgArr().addObjectsFromArray(photos)
let arr = weakSelf.ImgArr().arrayByAddingObjectsFromArray([UIImage(named:"images_01")!])
weakSelf.phontView.photoArray = arr
}
weakSelf.presentViewController(imagePickerVc, animated: true, completion: nil)
}
textView.addSubview(photosView)
}
func textViewDidChange(textView: UITextView) {
let textH: CGFloat = textView.text!.boundingRectWithSize(CGSizeMake(self.view.frame.size.width - 20, CGFloat(MAXFLOAT)), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)], context: nil).size.height
var frame = self.phontView.frame
frame.origin.y = 50+textH
self.phontView.frame = frame
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
是不是很简单
这里是Demo地址http://pan.baidu.com/s/1gfHMlMj
网友评论