swift 实现QQ好友列表功能
最近项目中有类似QQ好友列表功能,整理了一下,话不多说,直接上代码
import UIKit
class QQFriend: NSObject {
var name: String?
var intro: String?
init(dic: NSDictionary) {
super.init()
self.setValuesForKeys(dic as! [String : AnyObject])
}
}
import UIKit
class QQFriendGroup: NSObject {
var name: String?
var friends: NSArray?
var isOpen: Bool? = false
init(withDic dic: NSDictionary) {
super.init()
self.setValuesForKeys(dic as! [String : AnyObject])
let arrayFriend: NSMutableArray = NSMutableArray()
for friendDic in self.friends! {
let friend : QQFriend = QQFriend.init(dic: friendDic as! NSDictionary)
arrayFriend.add(friend)
}
self.friends = arrayFriend
}
}
import UIKit
//协议
protocol QQHeaderViewDelegate: NSObjectProtocol {
func headerViewDidClickedNameLab(headerView:QQHeaderView)
} class QQHeaderView: UITableViewHeaderFooterView {
weak var delegate:QQHeaderViewDelegate? var nameLabel: UILabel? = {
let nameLabel = UILabel()
return nameLabel
}() var arrow: UIImageView? = {
let arrow = UIImageView.init(image: UIImage(named: "orderDown"))
return arrow
}() var group: QQFriendGroup? {
didSet {
self.nameLabel?.text = group?.name
didMoveToSuperview()
}
} var clickNameBlock: ((Void)->())? = nil
var dividerView : UIView! = nil class func headerViewWithTableView(tableview: UITableView) -> QQHeaderView {
let headerID = "myHeader"
var header = tableview.dequeueReusableHeaderFooterView(withIdentifier: headerID)
if header == nil {
header = QQHeaderView.init(reuseIdentifier: headerID)
}
return header as! QQHeaderView
} override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier) let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(QQHeaderView.nameClick))
self.nameLabel?.isUserInteractionEnabled = true
self.arrow?.isUserInteractionEnabled = true
self.contentView.addGestureRecognizer(tap)
self.contentView.addSubview(nameLabel!)
self.contentView.addSubview(arrow!) let divideView = UIFactory.create_AView()
divideView.backgroundColor = UIColor.hrgb("cccccc")
self.contentView.addSubview(divideView)
self.dividerView = divideView } required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//点击展开或收起列表
func nameClick() {
self.group?.isOpen = !(self.group?.isOpen)!
// if ((self.delegate?.responds(to: Selector(("headerViewDidClickedNameLab:")))) != nil) {
// self.delegate?.headerViewDidClickedNameLab(headerView: self)
// }
if self.clickNameBlock != nil {
self.clickNameBlock!()
}
} override func didMoveToSuperview() {
super.didMoveToSuperview()
if self.group?.isOpen == true {
self.arrow?.transform = CGAffineTransform.init(rotationAngle: .pi)
}else {
self.arrow?.transform = CGAffineTransform.init(rotationAngle: 0)
}
} override func layoutSubviews() {
super.layoutSubviews()
self.nameLabel?.snp.makeConstraints({ (make) in
make.left.equalTo(15)
make.top.equalTo(0)
make.bottom.equalTo(0)
make.right.equalTo(-30)
})
self.arrow?.snp.makeConstraints({ (make) in
make.right.equalTo(-10)
make.width.height.equalTo(14)
make.centerY.equalTo(self.height * 0.5)
})
self.dividerView.snp.makeConstraints { (make) in
make.height.equalTo(0.5)
make.left.right.bottom.equalTo(0)
}
} }
import UIKit
extension ImitationQQ {
func numberOfSections(in tableView: UITableView) -> Int {
return (self.groups?.count)!
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let group: QQFriendGroup = self.groups![section] as! QQFriendGroup
return group.isOpen == true ? group.friends!.count : 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
cell.textLabel?.text = "\(indexPath.section)" + "\(indexPath.row)"
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 40
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header: QQHeaderView = QQHeaderView.headerViewWithTableView(tableview: tableView)
header.delegate = self
header.clickNameBlock = {
self.tabView.reloadData()
}
header.group = self.groups![section] as? QQFriendGroup
return header
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
}
extension ImitationQQ {
func headerViewDidClickedNameLab(headerView: QQHeaderView) {
self.tabView.reloadData()
}
}
class ImitationQQ: UIViewController, UITableViewDataSource, UITableViewDelegate, QQHeaderViewDelegate {
var tabView: UITableView! = nil
var dividerView : UIView! = nil
lazy var groups : NSArray? = {
var arr : NSMutableArray = NSMutableArray()
for i in 0..<3 {
let group: QQFriendGroup = QQFriendGroup.init(withDic: ["name":"\(i)" + "组", "friends":[["name":"00","intro":"挺好的"],["name":"01","intro":"挺好好的"],["name":"02","intro":"挺好好好的"],["name":"03","intro":"挺好好好好的"]]] as NSDictionary)
arr.add(group)
}
return arr
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.hrgb("f4f4f4")
self.title = "好友列表"
let tabView = UIFactory.create_ATableView(frame: CGRect.init(x: 0, y: 0.5, width: Screen_Width, height: kScreenHeight-64.5), delegate: self, dataSource: self, superView: self.view, type: .plain)
tabView.backgroundColor = UIColor.hrgb("f4f4f4")
tabView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
self.tabView = tabView
let divideView = UIFactory.create_AView()
divideView.frame = CGRect(x: 0, y: 0, width: Screen_Width, height: 0.5)
divideView.backgroundColor = UIColor.hrgb("cccccc")
self.view.addSubview(divideView)
self.dividerView = divideView
}
}
直接粘代码即可运行
swift 实现QQ好友列表功能的更多相关文章
- [iOS基础控件 - 6.9.3] QQ好友列表Demo TableView
A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组 code so ...
- ExpandableListView仿QQ好友列表
本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...
- Windows UIA自动化测试框架学习--获取qq好友列表
前段时间应公司要求开发一款针对现有WPF程序的自动化测试工具,在网上查资料找了一段时间,发现用来做自动化测试的框架还是比较多的,比如python的两个模块pywinauto和uiautomation, ...
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
- 仿QQ好友列表界面的实现
TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style ...
- (二十七)QQ好友列表的实现
QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...
- android 实现QQ好友列表
在某些Android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的.接触Android,也才一年的时间,大部分时间花在工作上(解bug...),界面上开发很少参与.自己维护的系统应用 ...
- 基于Qt的相似QQ好友列表抽屉效果的实现
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shuideyidi/article/details/30619167 前段时间在忙毕业设计, ...
- OS开发UI篇—使用UItableview完成一个简单的QQ好友列表
本文转自:http://www.cnblogs.com/wendingding/p/3763330.html 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableVi ...
随机推荐
- UVA1104 Chips Challenge
一.题目 有一个 \(n\times n\) 的矩阵,每个元素可能是 ..C./ 的其中一种,分别表示可以放置芯片.已经放置了芯片.不能放置芯片,你可以分别决定是否可以放置芯片的位置放置芯片. 最后需 ...
- Part 33 Angular nested scopes and controller as syntax
Working with nested scopes using $scope object : The following code creates 3 controllers - country ...
- 论文解读(Line)《LINE: Large-scale Information Network Embedding》
论文题目:<LINE: Large-scale Information Network Embedding>发表时间: KDD 2015论文作者: Jian Tang, Meng Qu ...
- CTF入门学习3->Web通信基础
Web安全基础 01 Web通信 这个部分重点介绍浏览器与Web服务器的详细通信过程. 01-00 URL协议 只要上网访问服务器,就离不开URL. URL是什么? URL就是我们在浏览器里输入的站点 ...
- bilibili动画下载视频批量改名(python)
bilib应用 在微软商店中下载哔哩哔哩动画,虽然软件UI古老,但是贵在稳定和支持下载 安装以后搜索自己想要的视频,然后缓存下载 下载后进入下载的路径 视频文件重命名 打开自动命令的程序或者py脚本, ...
- docker版本演变,安装,基本命令
1.docker 版本信息 Docker CE在17.03版本之前叫Docker Engine,版本号从0.1.0(2013-03-23)~1.13.1(2017-02-08),详见https://d ...
- 曼哈顿距离最小生成树 codechef Dragonstone
曼哈顿距离最小生成树 codechef Dragonstone 首先,对于每一个点来说有用的边只有它向它通过 x=0,y=0,y=x,y=-x 切出来的八个平面的最近点. 证明 我不会 反正当结论记住 ...
- 【R】write.table输出数据带有行名?
目录 问题 解决一 解决二 问题 这个问题应该很常见吧.R中输出数据框时,想要把行名和列名都输出.如果直接输出的话,输出的结果列名会往前移动一位,这显然不是我们想要的. 直接上例子: > a = ...
- SNP 过滤(一)
通用过滤 Vcftools(http://vcftools.sourceforge.net) 对vcf文件进行过滤 第一步:过滤最低质量低于30,次等位基因深度(minor allele count) ...
- Python编译工具Anaconda(含有spyder+jupyter)
Anaconda的下载和安装 官方的下载地址:https://www.anaconda.com/distribution/ 安装程序为一个可执行程序文件,下载完成后双击执行程序即可完成安装.安装过程一 ...