新浪微博客户端(26)-添加转发评论工具条

Posted 夜行过客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了新浪微博客户端(26)-添加转发评论工具条相关的知识,希望对你有一定的参考价值。

 

DJStatusToolBar.m

#import "DJStatusToolBar.h"

@interface DJStatusToolBar()

// 存放所有按钮
@property (nonatomic,strong) NSMutableArray *btns;
// 存放所有分割线
@property (nonatomic,strong) NSMutableArray *dividers;

@end


@implementation DJStatusToolBar


- (NSMutableArray *)btns {

    if (!_btns) {
        _btns = [NSMutableArray array];
    }
    return _btns;
}



- (NSMutableArray *)dividers {

    if (!_dividers) {
        _dividers = [NSMutableArray array];
    }
    return _dividers;
}




+ (instancetype)toolbar {

    return [[self alloc] init];

}



- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
     
        /* 添加转发等按钮 */
        [self setupBtn:@"转发" image:@"timeline_icon_retweet"];
        [self setupBtn:@"评论" image:@"timeline_icon_comment"];
        [self setupBtn:@"" image:@"timeline_icon_unlike"];
        
        /* 添加分割线 */
        [self setupDivider];
        [self setupDivider];
    }
    return self;
}



// 添加按钮
- (void)setupBtn:(NSString *)title image:(NSString *)imageName {

    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 0)];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self addSubview:btn];
    
    [self.btns addObject:btn];

}


- (void)setupDivider {

    UIImageView *divider = [[UIImageView alloc] init];
    divider.image = [UIImage imageNamed:@"timeline_card_bottom_line"];
    [self addSubview:divider];

    [self.dividers addObject:divider];
}



- (void)layoutSubviews {

    [super layoutSubviews];


    /* 设置按钮的frame */
    NSUInteger btnCount = self.btns.count;
    CGFloat btnW = self.width / btnCount;
    CGFloat btnH = self.height;
    for (int i = 0; i < btnCount; i++) {
        UIButton *btn = self.btns[i];
        btn.x = i * btnW;
        btn.y = 0;
        btn.width = btnW;
        btn.height = btnH;
    }
    
    /* 设置分割线的frame */
    NSUInteger dividerCount = self.dividers.count;
    for (int i = 0; i < dividerCount; i++) {
        UIImageView *divider = self.dividers[i];
        divider.width = 1;
        divider.height = btnH;
        divider.x = (i + 1) * btnW;
        divider.y = 0;
    }
    
}




@end

 

最终效果:

 

 

 

以上是关于新浪微博客户端(26)-添加转发评论工具条的主要内容,如果未能解决你的问题,请参考以下文章

Scrapy爬取新浪微博用户信息用户微博及其微博评论转发

新浪微博热门评论爬虫采集

新浪微博客户端(38)-显示键盘上的工具条

怎么破解新浪微博转发抽奖平台的抽奖次数,普通版同一条微博只能抽三次,怎么破解再获得一次啊!急啊!!

新浪微博转发抽奖活得怎么弄?

新浪微博抽奖被中技巧