How to make the scroll bar always visible in Xamarin forms in IOS device and shift the scroll bar to left side of the screen?
I tried this link:
Xamarin Forms ListView for iOS: Always Show ScrollBar
but getting exception that
Event registration is overwriting existing delegate. Either just use events or your own delegate: hupp.iOS.Models.CustomScrollDelegate UIKit.UIScrollView+_UIScrollViewDelegate
public class CustomScrollViewRenderer : ScrollViewRenderer
{
public UIView bar;
protected override async void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
// UIScrollView iosScrollView = (UIScrollView)NativeView;
this.ShowsVerticalScrollIndicator = ((CustomScrollViewLesson)e.NewElement).IsVerticalScrollbarEnabled;
this.ShowsHorizontalScrollIndicator = ((CustomScrollViewLesson)e.NewElement).IsHorizontalScrollbarEnabled;
this.IndicatorStyle = UIScrollViewIndicatorStyle.White;
this.ScrollIndicatorInsets = new UIEdgeInsets(0, 30, 0, 30);
this.FlashScrollIndicators();
//Hide the default Scroll Indicator.
this.ShowsVerticalScrollIndicator = false;
//Set Delegate
CustomScrollDelegate customScrollDelegate = new CustomScrollDelegate();
this.Delegate = customScrollDelegate;
//Create the background view of custom indicator.
double frameHeight = this.Frame.Size.Height;
double frameWidth = this.Frame.Size.Width;
double barBackgroundWidth = 6;
double statusBarHeight = 20; //this.ScrollIndicatorInsets = new UIEdgeInsets(0, 0, 0, this.Bounds.Size.Width - 10);
UIView barBackgroundView = new UIView();
CGRect barBVRect = new CGRect(frameWidth - barBackgroundWidth, statusBarHeight, barBackgroundWidth, frameHeight);
barBackgroundView.Frame = barBVRect;
barBackgroundView.BackgroundColor = UIColor.Gray;
barBackgroundView.Layer.CornerRadius = 2;
barBackgroundView.Layer.MasksToBounds = true;
//Create the bar of the custom indicator.
bar = new UIScrollView();
CGRect barRect = new CGRect(1, 0, 4, 0);
bar.Frame = barRect;
bar.BackgroundColor = UIColor.White;
bar.Layer.CornerRadius = 2;
bar.Layer.MasksToBounds = true;
//Add the views to the superview of the tableview.
barBackgroundView.AddSubview(bar);
this.Superview.AddSubview(barBackgroundView);//here also getting exception null value in superview.so i commented while debug
customScrollDelegate.bar = bar;
//Transfer the bar view to delegate.
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
Console.WriteLine("End of loading!!!");
double contentHeight = this.ContentSize.Height;
double frameHeight = this.Frame.Size.Height;
double barHeight = frameHeight * frameHeight / contentHeight;
//Reset the bar height when the table view finishes loading.
CGRect barRect = new CGRect(bar.Frame.X, bar.Frame.Y, bar.Frame.Width, barHeight);
bar.Frame = barRect;
}
}
public class CustomScrollDelegate : UIKit.UIScrollViewDelegate
{
public UIView bar;
double barY;
public override void Scrolled(UIScrollView scrollView)
{
double y = scrollView.ContentOffset.Y;
double contentHeight = scrollView.ContentSize.Height;
double frameHeight = scrollView.Frame.Size.Height;
double barHeight = frameHeight * frameHeight / contentHeight;
barY = y / (contentHeight - frameHeight) * (frameHeight - barHeight);
//Cut the bar Height when it over the top.
if (barY < 0)
{
barHeight = barHeight + barY;
barY = 0;
}
//Cut the bar height when it over the bottom.
if (barY > (frameHeight - barHeight))
{
barHeight = barHeight - (barY - (frameHeight - barHeight));
}
//Reset the barView rect. Let's move!!!
CGRect barRect = new CGRect(bar.Frame.X, barY, bar.Frame.Width, barHeight);
bar.Frame = barRect;
}
}
Please give a solution and thanks in advance