Search code examples
iosswiftuislider

RangeSeekSlider should start from Right to Left if language is Arabic


I am using RangeSeekSlider for displaying slider in my app. In normal case i.e. for all the LTR languages(Left to Right) it is working perfectly. But when working with languages like Arabic which require the slider to start from Right to Left i.e. opposite of the normal it is not working for me.

For your reference i have tried following piece of code but it did not worked for me,

@IBOutlet weak var sliderAmount: RangeSeekSlider!

override func viewDidLoad() {
    super.viewDidLoad()

    if AppUtils.checkIfArabic() == true{
        sliderAmount.semanticContentAttribute = .forceRightToLeft
    }else{
        self.sliderAmount.semanticContentAttribute = .forceLeftToRight
    }
    // Do any additional setup after loading the view.
}

Following is the screenshot of normal slider which is setup using below code

//MARK:- Setup Slider View

func setupSliderView(){
    sliderAmount.disableRange = true
    sliderAmount.enableStep = true
    sliderAmount.step = 500
    sliderAmount.delegate = self
    sliderAmount.minValue = 500.0
    lblAmt.text = "500"
    sliderAmount.maxValue = 25000.0
    sliderAmount.handleImage = UIImage(named: "ic_SliderHandler")
    sliderAmount.handleDiameter = 35.0
    sliderAmount.lineHeight = 7.0
    sliderAmount.hideLabels = true
    sliderAmount.tintColor = UIColor(displayP3Red: 235/255, green: 235/255, blue: 235/255, alpha: 1.0)
    sliderAmount.colorBetweenHandles = UIColor(displayP3Red: 135/255, green: 102/255, blue: 123/255, alpha: 1.0)
}

Current output:

enter image description here

TIA.


Solution

  • Solved the issue using following piece of code

    if L102Language.currentAppleLanguage() == "ar" { //Arabic
            UIView.animate(withDuration: 0.1) {
                self.sliderAmount.transform = CGAffineTransform(scaleX: -1, y: 1);
            }
        }
    

    So, the Output now is,

    enter image description here