Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议下划线宽度由Label宽度改为Label文字宽度,符合大家的使用习惯 #18

Closed
kane3000 opened this issue Nov 10, 2018 · 1 comment

Comments

@kane3000
Copy link

代码供参考:
方法1:
@objc private func titleLabelClick(_ tapGes : UITapGestureRecognizer)中:
if style.isShowBottomLine {
UIView.animate(withDuration: 0.25, animations: {
let bottomLineWidth = targetLabel.attributedText?.size().width ?? 0
let x = targetLabel.frame.origin.x + (targetLabel.frame.width - bottomLineWidth) / 2
self.bottomLine.frame.origin.x = x //targetLabel.frame.origin.x
self.bottomLine.frame.size.width = bottomLineWidth //targetLabel.frame.width
})
}
方法2:
private func setupBottomLineLayout() {
guard titleLabels.count - 1 >= currentIndex else { return }
let label = titleLabels[currentIndex]

    let bottomLineWidth = label.attributedText?.size().width ?? 0
    let x = label.frame.origin.x + (label.frame.width - bottomLineWidth) / 2
    
    bottomLine.frame.origin.x = x //label.frame.origin.x
    bottomLine.frame.origin.y = self.bounds.height - self.style.bottomLineHeight
    bottomLine.frame.size.width = bottomLineWidth//label.frame.width
    bottomLine.frame.size.height = self.style.bottomLineHeight
}
@Danie1s
Copy link
Owner

Danie1s commented Nov 12, 2018

谢谢你的建议。
style.isTitleViewScrollEnabled = true的时候,表示标签会比较多,所以默认会滑动,而且这时候会用到titleMargin这个属性,下划线宽度跟随文字宽度。
style.isTitleViewScrollEnabled = fasle的时候,表示标签少,默认是每个标签的宽度平分titleView的宽度,下划线宽度跟随标签宽度,这种样式也是比较多人需要的。

你所说的情况,如果标签多,可以直接用style.isTitleViewScrollEnabled = true,如果标签少,除了设置style.isTitleViewScrollEnabled = true,还需要自己算titleView的宽度,具体代码可以参考demo的第四种样式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants