新浪微博开发之三十四(微博工具栏view)
来源:互联网 发布:网络域名申请 编辑:程序博客网 时间:2024/06/05 04:20
// MyweiboToolBarView.h
// 新浪微博
//
// Created by Jose on 15-4-21.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import <UIKit/UIKit.h>
@class MyWeiboModel;
@interface MyweiboToolBarView : UIImageView
@property(nonatomic,assign)MyWeiboModel *weibo;
@end
*************************************************************************************************************
************************************************************************************************************
************************************************************************************************************
//
// MyweiboToolBarView.m
// 新浪微博
//
// Created by Jose on 15-4-21.
// Copyright (c) 2015年 jose. All rights reserved.
// 微博工具栏
#import "MyweiboToolBarView.h"
#import "UIImage+Extension.h"
#import "UIView+Extension.h"
#import "MyWeiboModel.h"
@interface MyweiboToolBarView()
/** 用来保存竖线 */
@property(nonatomic,strong)NSMutableArray *dividers;
/** 用来保存按钮 */
@property(nonatomic,strong)NSMutableArray *btns;
/** 评论按钮 */
@property(nonatomic,strong)UIButton *commentbtn;
/** 转发按钮 */
@property(nonatomic,strong)UIButton *repostbtn;
/** 赞按钮 */
@property(nonatomic,strong)UIButton *attitudebtn;
@end
@implementation MyweiboToolBarView
#pragma mark 懒加载模式
-(NSMutableArray *)dividers{
if (_dividers==nil) {
_dividers=[NSMutableArray array];
}
return _dividers;
}
-(NSMutableArray *)btns{
if (_btns==nil) {
_btns=[NSMutableArray array];
}
return _btns;
}
//初始化子控件
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
//设置可交互事件
self.userInteractionEnabled=YES;
self.image=[UIImage resizedimg:@"timeline_card_bottom_background"];
//添加按钮
_commentbtn=[self SetUpButtonWithIcon:@"timeline_icon_comment" Title:@"评论"];
_repostbtn=[self SetUpButtonWithIcon:@"timeline_icon_retweet" Title:@"转发"];
_attitudebtn=[self SetUpButtonWithIcon:@"timeline_icon_unlike" Title:@"赞"];
//添加竖线
[self SetUpDivider];
[self SetUpDivider];
}
return self;
}
//设置按钮
-(UIButton *)SetUpButtonWithIcon:(NSString *)icon Title:(NSString *)title{
UIButton *btn=[[UIButton alloc]init];
[btn setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
[btn setTitle:title forState:UIControlStateNormal];
[btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
btn.titleLabel.font=[UIFont systemFontOfSize:14];
btn.titleEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);
[btn setBackgroundImage:[UIImage imageNamed:@"common_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
btn.adjustsImageWhenDisabled=NO;
[self addSubview:btn];
[self.btns addObject:btn];
return btn;
}
//设置竖线
-(void)SetUpDivider{
UIImageView *divider=[[UIImageView alloc]init];
divider.image=[UIImage imageNamed:@"timeline_card_bottom_line"];
divider.contentMode=UIViewContentModeCenter;
[self addSubview:divider];
//注意self的使用
[self.dividers addObject:divider];
}
//布局子控件
-(void)layoutSubviews{
[super layoutSubviews];
int btncounts=(int)_btns.count;
CGFloat btnw=self.width/btncounts;
CGFloat btnh=self.height;
for (int i=0; i<btncounts; i++) {
UIButton *btn=_btns[i];
btn.width=btnw;
btn.height=btnh;
btn.y=0;
btn.x=i*btnw;
}
int dividercount=(int)_dividers.count;
for (int i=0; i<dividercount; i++) {
UIImageView *divider=_dividers[i];
divider.width=2;
divider.height=btnh;
divider.x=(1+i)*btnw;
divider.y=0;
}
}
//重写set方法,传入微博数据
-(void)setWeibo:(MyWeiboModel *)weibo{
_weibo=weibo;
[self SetUpButtonTitle:_commentbtn Count:weibo.comments_count DefaultTitle:@"评论"];
[self SetUpButtonTitle:_repostbtn Count:weibo.reposts_count DefaultTitle:@"转发"];
[self SetUpButtonTitle:_attitudebtn Count:weibo.attitudes_count DefaultTitle:@"赞"];
}
//设置标题
-(void)SetUpButtonTitle:(UIButton *)button Count:(int)count DefaultTitle:(NSString *)defaulttitle{
if (count>=10000) {
defaulttitle=[NSString stringWithFormat:@"%.1f万",count/10000.0];
//用空字符串替换所有的.0
defaulttitle=[defaulttitle stringByReplacingOccurrencesOfString:@".0" withString:@""];
}
else if (count>0){
defaulttitle=[NSString stringWithFormat:@"%d",count];
}
[button setTitle:defaulttitle forState:UIControlStateNormal];
}
@end
- 新浪微博开发之三十四(微博工具栏view)
- 新浪微博开发之十九(文本框工具栏)
- 新浪微博开发之二十(中间工具栏控制器)
- 新浪微博开发之三十六(微博view)
- 新浪微博开发之二十九(原创微博view)
- 新浪微博开发之三十一(转发微博view)
- 新浪微博开发之php开发
- IOS开发之新浪微博OAuth2
- 新浪微博开发之十四(AFNetworking的使用 )
- 新浪微博开发之十五(MBProgressHUD的使用)
- 新浪微博开发之十六(封装网络工具)
- 新浪微博开发之十七(图片工具)
- 新浪微博开发之十八(文本框)
- 新浪微博开发之二十七(全局变量)
- 新浪微博开发之三十五(微博frame)
- VS2013/MFC编程入门之三十四(工具栏:工具栏资源及CToolBar类)
- 新浪微博android开发
- 新浪微博开发笔记
- LeetCode 2 Add Two Numbers
- odoo8.0下selection_add的使用
- 利用xcodebuild命令导出ipa包,并签名
- ssh后台运行 linux重定向及nohup不输出的方法
- 指数分布和泊松过程(二)
- 新浪微博开发之三十四(微博工具栏view)
- lightOJ 1138 Trailing Zeroes (III)
- android TouchEvent事件传递
- Android中单位值得使用
- 對Report式ListView進行排序
- 利用jcifs进行NTLM协议认证,生成ws访问客户端
- Android离线帮助文档打开慢的解决办法
- lightOJ 1197 Help Hanzo 两阶段素数筛选
- 黑马程序员----集合框架