• 新浪微博客户端(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

    最终效果:

     

     

  • 相关阅读:
    DatePicker 日期选择器 split-panels 数组的时候,清空这个费劲啊,最后走的后门
    英语音标总结
    前台发布地址动态获取 本机地址
    SecureCRT windows 登录 linux
    The History of the English language 英语语音的起源
    iview 部分表单验证
    iView 表单验证 如果prop字段和表单里的字段对不上,会触发校验,提示错误信息
    hdu4370 0 or 1
    即时通讯上手必备知识点
    不使用Math.random实现随机数。
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6071683.html
Copyright © 2020-2023  润新知