zoukankan      html  css  js  c++  java
  • 新浪微博客户端(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

    最终效果:

     

     

  • 相关阅读:
    汉语-词语-转世:百科
    汉语-词语-往生:百科
    中缀表达式值
    车厢调度(train.cpp)
    字符串匹配问题
    计算(calc.cpp)
    2、括弧匹配检验
    2058 括号序列
    7909:统计数字
    1007. 计算余数
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6071683.html
Copyright © 2011-2022 走看看