//创建tableview中头部的文件
#define kPadding 10 #define kIconWidth 100
#define kIconHeight 100 #define kCountButtonHeight 35
#define kCountSize 12
#define kCountButtonWidth 55 #define kNameSize 15
#define kDescSize 10 #define kBtnFriend 1
#define kBtnFollower 2 #define kGlobalBg [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1] #import "ProfileHeaderView.h"
#import "User.h"
#import <QuartzCore/QuartzCore.h>
#import "ASIHTTPRequest.h"
#import "FriendController.h"
#import "FollowerController.h" @interface ProfileHeaderView() {
UIImageView *_icon;
UILabel *_name;
UILabel *_desc;
UILabel *_status; UIButton *_friends;
UIButton *_followers;
}
@end @implementation ProfileHeaderView
#pragma mark 监听按钮点击
- (void)btnClick:(UIButton *)btn { FriendshipController *vc = nil; if (btn.tag == kBtnFollower) {
// 粉丝
vc = [[[FollowerController alloc] init] autorelease];
vc.title = [NSString stringWithFormat:@"%@的粉丝", self.user.screenName];
} else {
// 关注
vc = [[[FriendController alloc] init] autorelease];
vc.title = [NSString stringWithFormat:@"%@的关注", self.user.screenName];
} vc.uid = self.user.uid;
[self.controller.navigationController pushViewController:vc animated:YES];
} #pragma mark 返回数目按钮的文字
- (NSString *)countText:(int)count title:(NSString *)title {
NSString *countTitle = nil;
if (count < ) {
countTitle = [NSString stringWithFormat:@"%i", count];
} else {
CGFloat countValue = count/10000.0;
countTitle = [NSString stringWithFormat:countValue>=?@"%.0f万":@"%.1f万", countValue];
} return [NSString stringWithFormat:@"%@\n%@", countTitle, title];
} #pragma mark 创建一个按钮
- (UIButton *)buttonWithSelector:(SEL)selector x:(CGFloat)x y:(CGFloat)y {
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(x, y, kCountButtonWidth, kCountButtonHeight)] autorelease];
button.titleLabel.font = [UIFont systemFontOfSize:kCountSize];
[button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.numberOfLines = ;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage resizeImage:@"skin_cell_background.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage resizeImage:@"skin_cell_background_highlighted.png"] forState:UIControlStateHighlighted];
[button setBackgroundImage:[UIImage resizeImage:@"skin_cell_background_highlighted.png"] forState:UIControlStateDisabled];
return button;
} #pragma mark - user的setter
- (void)setUser:(User *)user {
if (_user != user) {
[_user release];
_user = [user retain]; // 下载图片
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:user.avatarLarge]];
request.delegate = self;
[request startAsynchronous]; // 设置名称
_name.text = user.screenName; // 设置简介
NSString *descText = (user.descs==nil || [@"" isEqualToString:user.descs])?@"这个人比较懒,什么也没写":[NSString stringWithFormat:@"简介:\n%@", user.descs];
_desc.text = descText; // 设置数目
[_friends setTitle:[self countText:user.friendsCount title:@"关注"] forState:UIControlStateNormal];
[_followers setTitle:[self countText:user.followersCount title:@"粉丝"] forState:UIControlStateNormal]; // 微博数量
_status.text = [NSString stringWithFormat:@" 共%i条微博", user.statusesCount];
}
} #pragma mark - 生命周期方法
- (id)init {
if (self = [super init]) {
CGSize winSize = [UIScreen mainScreen].bounds.size;
// 顶部
UIImageView *topView = [[[UIImageView alloc] initWithFrame:CGRectMake(, , winSize.width, kIconHeight + *kPadding)] autorelease];
topView.image = [UIImage imageNamed:@"profile_cover_background.png"];
[self addSubview:topView]; // 头像
CGFloat iconX = kPadding;
CGFloat iconY = kPadding;
_icon = [[[UIImageView alloc] initWithFrame:CGRectMake(iconX, iconY, kIconWidth, kIconHeight)] autorelease];
_icon.image = [UIImage imageNamed:@"avatar_default_big.png"];
_icon.layer.cornerRadius = ;
_icon.layer.masksToBounds = YES;
[topView addSubview:_icon]; // 昵称
CGFloat nameX = iconX + kIconWidth + kPadding;
CGFloat nameY = iconY;
CGFloat nameWidth = winSize.width - nameX - kPadding;
CGFloat nameHeight = kNameSize;
_name = [[[UILabel alloc] init] autorelease];
_name.frame = CGRectMake(nameX, nameY, nameWidth, nameHeight);
_name.backgroundColor = [UIColor clearColor];
_name.font = [UIFont systemFontOfSize:kNameSize];
[topView addSubview:_name]; // 简介
CGFloat descX = nameX;
CGFloat descY = nameY + nameHeight + kPadding;
CGFloat descWidth = nameWidth;
CGFloat descheight = kIconHeight - descY;
_desc = [[[UILabel alloc] init] autorelease];
_desc.frame = CGRectMake(descX, descY, descWidth, descheight);
_desc.font = [UIFont systemFontOfSize:kDescSize];
_desc.backgroundColor = [UIColor clearColor];
_desc.numberOfLines = ;
_desc.textColor = [UIColor whiteColor];
[topView addSubview:_desc]; // 数目
CGFloat countViewY = topView.frame.size.height;
CGFloat countViewHeight = kCountButtonHeight + *kPadding;
UIView *countView = [[[UIView alloc] initWithFrame:CGRectMake(, countViewY, winSize.width, countViewHeight)] autorelease];
countView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:];
[self addSubview:countView]; // 关注
CGFloat friendsX = kPadding;
CGFloat friendsY = kPadding;
_friends = [self buttonWithSelector:@selector(btnClick:) x:friendsX y:friendsY];
_friends.tag = kBtnFriend;
[countView addSubview:_friends]; // 粉丝
CGFloat followersX = friendsX + kCountButtonWidth + kPadding;
CGFloat followersY = friendsY;
_followers = [self buttonWithSelector:@selector(btnClick:) x:followersX y:followersY];
_followers.tag = kBtnFollower;
[countView addSubview:_followers]; // 顶部的线
CGFloat bottomHeight = ;
UIView *bottom = [[[UIView alloc] initWithFrame:CGRectMake(, countViewHeight - bottomHeight, winSize.width, bottomHeight)] autorelease];
bottom.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"profile_shadow_bottom.png"]];
[countView addSubview:bottom]; // 微博数
CGFloat statusX = ;
CGFloat statusY = countViewY + countViewHeight + ;
CGFloat statusHeight = kCountSize + kPadding;
_status = [[[UILabel alloc] init] autorelease];
_status.backgroundColor = kGlobalBg;
_status.frame = CGRectMake(statusX, statusY, winSize.width, statusHeight);
_status.font = [UIFont systemFontOfSize:kCountSize];
[self addSubview:_status]; self.frame = CGRectMake(, , winSize.width, statusY + statusHeight);
}
return self;
} - (void)dealloc {
[_user release];
[super dealloc];
} #pragma mark - ASI代理
- (void)requestFinished:(ASIHTTPRequest *)request {
_icon.image = [UIImage imageWithData:[request responseData]];
}
@end
//  个人资料的头部

#import <UIKit/UIKit.h>
@class User;
@protocol ASIHTTPRequestDelegate;
@interface ProfileHeaderView : UIView <ASIHTTPRequestDelegate>
@property (nonatomic, retain) User *user;
@property (nonatomic, assign) UIViewController *controller;
@end

tableview中头部信息的更多相关文章

  1. 新浪微博中tableview中头部信息

    摘自http://www.cnblogs.com/gcb999/p/3151665.html #import <UIKit/UIKit.h> @class User; @protocol ...

  2. HTTP消息中header头部信息的讲解

    HTTP Request的Header信息 1.HTTP请求方式 如下表: GET 向Web服务器请求一个文件 POST 向Web服务器发送数据让Web服务器进行处理 PUT 向Web服务器发送数据并 ...

  3. HTTP消息中Header头部信息整理

    1.HTTP请求方式 GET 向Web服务器请求一个文件 POST 向Web服务器发送数据让Web服务器进行处理 PUT 向Web服务器发送数据并存储在Web服务器内部 HEAD 检查一个对象是否存在 ...

  4. sublime3中如何快速生成html头部信息

    前提要安装Emmet 插件:已经结束了啊,不要以为下面的操作跟问题有关,下面是具体的生成头部信息方法 输入下边加粗的缩写,然后Tab,就可以了: 生成html4.01 Transitional用 ht ...

  5. 【转】HTTP 头部解释,HTTP 头部详细分析,最全HTTP头部信息

    HTTP 头部解释 ========================================================================================== ...

  6. 深入理解ajax系列第三篇——头部信息

    前面的话 每个HTTP请求和响应都会带有相应的头部信息,其中有的对开发人员有用.XHR对象提供了操作头部信息的方法.本文将详细介绍HTTP的头部信息 默认信息 默认情况下,在发送XHR请求的同时,还会 ...

  7. 深入理解ajax系列第六篇——头部信息

    前面的话 每个HTTP请求和响应都会带有相应的头部信息,其中有的对开发人员有用.XHR对象提供了操作头部信息的方法.本文将详细介绍HTTP的头部信息 默认信息 默认情况下,在发送XHR请求的同时,还会 ...

  8. nginx 获取自定义header头部信息

    为了排查线上的bug,需要在nginx的日志中,打印客户端上传上来的header头部信息,同时头部信息是自定义的.在尝试多重方案后,找到解决方法: log_format dm '"$remo ...

  9. Html5新特性之文档声明和头部信息

    Html5推出的新内容比较多,本文我们来介绍两个重点内容,文档类型声明和头部信息. 无论是Html4.01还是XHtml1.0,所有文档的开头都会有文档声明<!DOCTYPE>标签来声明它 ...

随机推荐

  1. Android教你怎样一步步打造通用适配器

    前言 在Android开发中ListView是最为经常使用的控件之中的一个,基本每一个应用都会涉及到它,要使用ListView列表展示,就不可避免地涉及到另外一个东西--Adapter,我们都知道,A ...

  2. 添加PMD插件扫描潜在的bug

    上一节使用checkstyle来规范你的项目主要解决了代码编码规范问题,比如缩进换行等.这次继续代码健康工具类PMD. 什么是PMD PMD真的不像checkstyle这样的东西所见即所得啊,去官网找 ...

  3. 【GRPC】GRPC-负载均衡

    GRPC-负载均衡 grpc nginx_百度搜索 grpc(1):Centos 安装java的grpc服务,使用haproxy进行负载均衡,nginx不支持 - freewebsys的专栏 - CS ...

  4. NLP资源

    http://www.cs.columbia.edu/~mcollins/notes-spring2013.html http://web.stanford.edu/class/cs224n/syll ...

  5. 基于CRF的中文分词

    http://biancheng.dnbcw.info/java/341268.html CRF简介 Conditional Random Field:条件随机场,一种机器学习技术(模型) CRF由J ...

  6. 转: git使用时让http记住帐号密码

    见 http://git.mydoc.io/?t=154710 https 方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受 https 带来的极速 按照以下设置记住密 ...

  7. GPUImage API 文档之GPUImageOutput类

    GPUImageOutput类将静态图像纹理上传到OpenGL ES中,然后使用这些纹理去处理进程链中的下一个对象.它的子类可以获得滤镜处理后的图片功能.[本文讲的很少,由于有许多地方不清楚,以后会更 ...

  8. 免费素材:气球样式的图标集(PSD, SVG, PNG)

    本地下载 一套30枚设计精良的气泡式圆形图标,两种款式供您选择,相信你会喜欢!

  9. Discuz常见小问题-_如何修改网站LOGO

    1 界面-风格管理,点击编辑 2 默认的LOGO图片叫做logo.png,存放在X:\PHPNow\htdocs\Discuz\upload\static\image\common文件夹下面,其中X是 ...

  10. ArcGIS10.3新体验

    自2012年ESRI更新10.2以后,终于在2014年12月8日,官方推出了10.3版本,前几天忙于抢票,今天终于可以在虚拟机中体验一把. 由于使用的是预览版,所有安装包只有800多M,包括桌面核心程 ...