Skip to content

解决EYCheckBoxButton 字数超出屏幕不显示问题 #3

Description

@ByteRax

解决代码

  • (EYCheckBoxButton *)tagButtonWithTag:(NSString *)tag
    {
    EYCheckBoxButton *tagBtn = [[EYCheckBoxButton alloc] init];
    tagBtn.colorBg=_colorTagBg;
    tagBtn.colorTagUnSelected=_colorTagUnselected;
    tagBtn.colorTagBorder=_colorTagBoard;
    tagBtn.colorText=_colorTag;
    tagBtn.titleLabel.lineBreakMode = 0;
    tagBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    tagBtn.colorTagUnBorder=_colorTagUnSelectBoard;
    tagBtn.colorUnSelectBg=_colorTagUnSelectBg;
    tagBtn.selected=YES;
    [tagBtn.titleLabel setFont:_fontTag];
    [tagBtn setBackgroundColor:_colorTagBg];
    [tagBtn setTitleColor:_colorTag forState:UIControlStateNormal];
    [tagBtn addTarget:self action:@selector(handlerTagButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [tagBtn setTitle:tag forState:UIControlStateNormal];

    CGRect btnFrame;
    btnFrame.size.height = _tagHeight;
    tagBtn.layer.cornerRadius = btnFrame.size.height * self.borderRadius;
    CGFloat width=[tagBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:_fontTag}].width + (tagBtn.layer.cornerRadius * 2.0f) + _textPaddingSize.width_2;
    if (width>_svContainer.contentSize.width) {
    int widhts=_svContainer.contentSize.width-(tagBtn.layer.cornerRadius * 2.0f) + _textPaddingSize.width_2-15;
    int height=(ceilf(width/widhts))*[tagBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:_fontTag}].height+5;
    _tagHeight=height;
    btnFrame.size.height = height;
    btnFrame.size.width = widhts;
    }else{
    btnFrame.size.width = width;
    }

    tagBtn.frame=btnFrame;
    return tagBtn;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions