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

JXSegmentedTitleImageDataSource (图片在上或者在下的时候宽度计算) #219

Closed
lianshuaishuai opened this issue Dec 8, 2022 · 4 comments

Comments

@lianshuaishuai
Copy link

open override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat {
    var width = super.preferredSegmentedView(segmentedView, widthForItemAt: index)
  
    if itemWidth == JXSegmentedViewAutomaticDimension {
        switch titleImageType {
        case .leftImage, .rightImage:
            width += titleImageSpacing + imageSize.width
        case .topImage, .bottomImage:
            width = max(itemWidth, imageSize.width)
        case .onlyImage:
            width = imageSize.width
        case .onlyTitle:
            break
        }
    }
    return width
}

上面应该取width 不应该用itemWidth

@LemonChao
Copy link

我也遇到了同样的问题,新版本会修复吗 @pujiaxin33

@lianshuaishuai
Copy link
Author

我也遇到了同样的问题,新版本会修复吗 @pujiaxin33

我尝试了继承 JXSegmentedTitleImageDataSource
重写
override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat {
var width = itemWidthIncrement
if itemWidth == JXSegmentedViewAutomaticDimension {
width += (dataSource[index] as! JXSegmentedTitleItemModel).textWidth
}else {
width += itemWidth
}

    if itemWidth == JXSegmentedViewAutomaticDimension {
        switch titleImageType {
        case .leftImage, .rightImage:
            width += titleImageSpacing + imageSize.width
        case .topImage, .bottomImage:
            width = max(width, imageSize.width)
        case .onlyImage:
            width = imageSize.width
        case .onlyTitle:
            break
        }
    }
    return width
}

但是 func segmentedView(_ segmentedView: JXSegmentedView, widthForItemContentAt index: Int) -> CGFloat 无法重写 (使用pod管理的 此方法使用的public) 查看了一下 如果不是一些特定的 例如缩放 获取模型中的宽度等 这个方法不重写 好像也不影响
如果有问题 请指出

@LemonChao
Copy link

我是这样重写的,宽度就正常了

   override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat {
        var width = (dataSource[index] as! JXSegmentedTitleImageItemModel).textWidth
        if itemWidth == JXSegmentedViewAutomaticDimension {
            switch titleImageType {
            case .leftImage, .rightImage:
                width += titleImageSpacing + imageSize.width
            case .topImage, .bottomImage:
                width = max(width, imageSize.width)
            case .onlyImage:
                width = imageSize.width
            case .onlyTitle:
                break
            }
        }
        return width
    }

@pujiaxin33
Copy link
Owner

我是这样重写的,宽度就正常了

   override func preferredSegmentedView(_ segmentedView: JXSegmentedView, widthForItemAt index: Int) -> CGFloat {
        var width = (dataSource[index] as! JXSegmentedTitleImageItemModel).textWidth
        if itemWidth == JXSegmentedViewAutomaticDimension {
            switch titleImageType {
            case .leftImage, .rightImage:
                width += titleImageSpacing + imageSize.width
            case .topImage, .bottomImage:
                width = max(width, imageSize.width)
            case .onlyImage:
                width = imageSize.width
            case .onlyTitle:
                break
            }
        }
        return width
    }

已参考,修复。

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

3 participants