LXMRulerView icon indicating copy to clipboard operation
LXMRulerView copied to clipboard

使用阿拉伯语时, 尺的第一个刻度没有数字

Open zixuan-espressoft opened this issue 5 years ago • 4 comments

在阿拉伯语会有从右到左(RTL)的界面反转,所以尺的0是从第二个刻度开始,导致准确性有失误。谢谢。

zixuan-espressoft avatar Jun 17 '19 08:06 zixuan-espressoft

IMG_0178 Uploading IMG_0177.PNG…

zixuan-espressoft avatar Jun 17 '19 08:06 zixuan-espressoft

@zixuan-espressoft 我还没考虑到阿拉伯语的情况。。。现在也没有时间去研究,你看看按你自己的需求修改一下源码来用吧。里面核心就是一个CollectionView的offset计算而已

Phelthas avatar Jun 18 '19 02:06 Phelthas

解决了,只需更改以下,🙏谢谢你的尺,用起来很方便!

LXMRulerView.m

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (self.rulerType != LXMRulerTypePicker) {
        return;
    }
    CGFloat offsetX = scrollView.contentOffset.x;
    if (Arabic) {
        self.currentValue = (self.rulerStyle.maxValue) - ((offsetX + scrollView.contentInset.left) / self.rulerStyle.rulerSpacing * self.rulerStyle.accuracy + self.rulerStyle.minValue);
    }else{
        self.currentValue = (offsetX + scrollView.contentInset.left) / self.rulerStyle.rulerSpacing * self.rulerStyle.accuracy + self.rulerStyle.minValue;
    }
    //    if (self.currentValue > self.rulerStyle.maxValue) {
    //        self.currentValue = self.rulerStyle.maxValue;
   //    }
//    if (self.currentValue < self.rulerStyle.minValue) {
//        self.currentValue = self.rulerStyle.minValue;
//    }
    if (self.valueChangeCallback) {
        self.valueChangeCallback(self.currentValue);
    }
}

-(void)updateCurrentValue:(CGFloat)value animated:(BOOL)animated {
    if (self.rulerType != LXMRulerTypePicker) {
        return;
    }
    if (value > self.rulerStyle.maxValue) {
        value = self.rulerStyle.maxValue;
    }
    if (value < self.rulerStyle.minValue) {
        value = self.rulerStyle.minValue;
    }
    self.currentValue = value;
    
    CGFloat offsetX;
    
    if (Arabic) {
        offsetX = (self.rulerStyle.maxValue - self.currentValue) * self.rulerStyle.rulerSpacing / self.rulerStyle.accuracy - self.collectionView.contentInset.right;
    }else{
        offsetX = (self.currentValue - self.rulerStyle.minValue) * self.rulerStyle.rulerSpacing / self.rulerStyle.accuracy - self.collectionView.contentInset.left;
    }
    [self.collectionView setContentOffset:CGPointMake(offsetX, 0) animated:animated];
}

LXMRulerCell.m

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGRect leadingRect = self.leadingLabel.frame;
    if (Arabic) {
        leadingRect.origin.x = CGRectGetWidth(self.bounds) - (leadingRect.size.width / 2) - 2;
    }else{
        leadingRect.origin.x = -(leadingRect.size.width / 2) + 2;
    }
    leadingRect.origin.y = self.rulerStyle.longLineDistance + 4;
    self.leadingLabel.frame = leadingRect;
    
    CGRect trailingRect = self.trailingLabel.frame;
    if (Arabic) {
        trailingRect.origin.x = -(trailingRect.size.width / 2) + 2;
    }else{
        trailingRect.origin.x = CGRectGetWidth(self.bounds) - (trailingRect.size.width / 2) - 2;
    }
    trailingRect.origin.y = self.rulerStyle.longLineDistance + 4;
    self.trailingLabel.frame = trailingRect;
}

zixuan-espressoft avatar Jun 18 '19 04:06 zixuan-espressoft

@zixuan-espressoft 谢谢,如果你测试过没问题的话,可以提交一个pullRequest,说不定可以帮到其他人

Phelthas avatar Jun 19 '19 01:06 Phelthas