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 ...
随机推荐
- Tcpdump 常用命令、参数记录
一.介绍 一个关于Centos Tcpdump 的个人工作总结. 二.参数介绍: 1. -i: 指定要进行抓包的网卡 2.-s0 :表示每个报文的大小是接收到的指定大小,如果没有这个选项,则超过 ...
- CSS学习笔记:定位属性position
目录 一.定位属性简介 二.各属性值的具体功能 1. relative 2. absolute 3. fixed 三.三种定位属性的效果总结 参考资料:https://www.bilibili.com ...
- Ubuntu 安装 mysql 报错 "update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在"
解决方法: sudo cp /etc/mysql/my.cnf /etc/mysql/mysql.cnf 偷梁换柱-! 如果想更新mysql的源方法如下: wget http://dev.mysql. ...
- 跟着老猫来搞GO,基础进阶
回顾一下上一篇博客,主要是和大家分享了GO语言的基础语法,其中包含变量定义,基本类型,条件语句,循环语句.那本篇呢就开始和大家同步一下GO语言基础的进阶. 函数的定义 上次其实在很多的DEMO中已经写 ...
- python调试出现报错:SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb0 in position 9: invalid start byte
原因:如图,代码里字符串里加上汉字就会报相关错误: 解决办法:开头加上 #-*-coding:GBK -*- 即可解决
- 【GIS】GeoServer服务Authkey配置记录
特别感谢:https://www.cnblogs.com/HandyLi/p/8624507.html 1.服务受控配置 2.授权方式 3.Url模式配置 4.Authkey密钥配置 5.使用 在wm ...
- mybatis插入数据时处理为null的属性
在做项目的时候,数据库中的所有字段被设置为全都不能为null,但是在我们开发过程中,插入一些记录的时候,实体类中的一些字段如果页面没有传入,则默认就会被设置为null,这样的话,在执行插入语句的时候, ...
- Python学习周总结(二)
Python-SecondWeek知识汇总 本周学了好多内容,最头痛的地方还是自己的思维逻辑不过关,还是敲的代码比较少,一个员工管理系统,第一天写搞得头大 ,结果第三遍自己突然懂了,个人的努力才是自己 ...
- Asp.Net Core中简单使用日志组件log4net
本文将简单介绍在.NET 6中使用log4net的方法,具体见下文范例. 1.首先新建一个ASP.NET Core空项目 2.通过Nuget包管理器安装下面两个包 log4net Microsoft. ...
- [luogu5344]逛森林
由于没有删边操作,可以先建出整棵森林,之后再用并查集判断是否连通,若连通必然与最后的森林相同 但如果用树链剖分+线段树的形式来优化建图,更具体如下: 建立两颗线段树,左边从儿子连向父亲,右边从父亲连向 ...