swift2.0仿微信界面,可滑动cell,自定义图片选择器。。。
LGWeChatKit是我再学习swift的过程中慢慢修改的,对于很多swift的编程特性还有很多不了解的地方,所以再代码里面可能看到一些和OC类似的代码形式
,希望有什么不足的地方大家帮忙提出,如果你喜欢的话,请给个大大的Star吧,点下右上角就可以啦谢谢啦~
##QQ群
创建一个swift技术讨论群,欢迎各位大神加入交流 469492027, 你可以通过项目的设置项中关注我的微博噢~~~
请在xcode7、IOS9.0以上版本上运行此程序demo,否则会有一些错误提示~~
再使用的时候,只要继承LGConversionListBaseCell就可以了。
var cell = tableView.dequeueReusableCellWithIdentifier("messageListCell") as? LGConversionListCell
if cell == nil {
let leftButtons = [UIButton.createButton("取消关注", backGroundColor: UIColor.purpleColor())]
let rightButtons = [UIButton.createButton("标记已读", backGroundColor: UIColor.grayColor()),UIButton.createButton("删除", backGroundColor: UIColor.redColor())]
cell = LGConversionListCell(style: .Subtitle, reuseIdentifier: "messageListCell")
cell?.delegate = self
cell?.viewModel = updateCell()
cell?.setLeftButtons(leftButtons)
cell?.setRightButtons(rightButtons)
}
return cell!
基于新的photo.framework,告别繁琐的asset操作,使用起来非常的方便
获取相册流,包括自定义的文件夹
func getCollectionList() {
let albumOptions = PHFetchOptions()
albumOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let userAlbum = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .AlbumRegular, options: nil)
userAlbum.enumerateObjectsUsingBlock { (collection, index, stop) -> Void in
let coll = collection as! PHAssetCollection
let assert = PHAsset.fetchAssetsInAssetCollection(coll, options: nil)
if assert.count > 0 {
let model = PHRootModel(title: coll.localizedTitle!, count: assert.count, fetchResult: assert)
self.collections.value.append(model)
}
}
let userCollection = PHCollectionList.fetchTopLevelUserCollectionsWithOptions(nil)
userCollection.enumerateObjectsUsingBlock { (list, index, stop) -> Void in
let list = list as! PHAssetCollection
let assert = PHAsset.fetchAssetsInAssetCollection(list, options: nil)
if assert.count > 0 {
let model = PHRootModel(title: list.localizedTitle!, count: assert.count, fetchResult: assert)
self.collections.value.append(model)
}
}
}
获取每一张图片,options是可选属性,可以设置图片的质量等
PHImageManager.defaultManager().requestImageForAsset(collection?.fetchResult.lastObject as! PHAsset, targetSize: CGSizeMake(50, 60), contentMode: .AspectFit, options: nil) { (image, _: [NSObject : AnyObject]?) -> Void in
if image == nil {
return
}
cell?.imageView?.image = image
self.tableView.reloadData()
}
支持文字粘贴复制等功能
let pressIndexPath = tableView.indexPathForRowAtPoint(gestureRecognizer.locationInView(tableView))!
tableView.selectRowAtIndexPath(pressIndexPath, animated: false, scrollPosition: .None)
let menuController = UIMenuController.sharedMenuController()
let localImageView = gestureRecognizer.view!
menuController.setTargetRect(localImageView.frame, inView: localImageView.superview!)
menuController.menuItems = [UIMenuItem(title: "复制", action: "copyAction:"), UIMenuItem(title: "转发", action: "transtionAction:"), UIMenuItem(title: "删除", action: "deleteAction:"), UIMenuItem(title: "更多", action: "moreAciton:")]
menuController.setMenuVisible(true, animated: true)
使用Contacts.framework,该功能再IOS9以上可以使用!
let store = CNContactStore()
let keyToFetch = [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName), CNContactImageDataKey, CNContactPhoneNumbersKey]
let fetchRequest = CNContactFetchRequest(keysToFetch: keyToFetch)
var contacts = [CNContact]()
do {
try store.enumerateContactsWithFetchRequest(fetchRequest, usingBlock: { (contact, stop) -> Void in
contacts.append(contact)
})
} catch let error as NSError {
print(error.localizedDescription)
}
MIT