Colour for ScrollBar in ScrollView #20992
Unanswered
ThanhHaiDang96
asked this question in
Ideas
Replies: 1 comment 4 replies
-
You can access the platform properties and views to account for this. For example on iOS / Mac Catalyst: https://developer.apple.com/documentation/uikit/uiscrollviewindicatorstyle?language=objc using Microsoft.Extensions.Logging;
using Microsoft.Maui.Platform;
#if IOS || MACCATALYST
using UIKit;
#endif
namespace ScrollBarColor;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureMauiHandlers(handlers =>
{
ThemeScrollBar();
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
private static void ThemeScrollBar()
{
Microsoft.Maui.Handlers.ScrollViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if IOS
handler.PlatformView.Scrolled += (s, e) =>
{
var scrollView = (UIScrollView)s;
var verticalIndicator = scrollView.Subviews.Last();
verticalIndicator.BackgroundColor = UIColor.Red;
};
#elif MACCATALYST
handler.PlatformView.IndicatorStyle = UIScrollViewIndicatorStyle.White;
#elif ANDROID
// Android customization
#elif WINDOWS
// Windows customization
#endif
});
}
} scroll_indicator.mp4Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-03-05.at.08.26.25.mp4 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
Hi,
How can I set color for scroll bar in a ScrollView?
I have a VerticalStackLayout inside a ScrollView. The StackLayout has background is Black, so I cannot show the ScrollBar with default color.
Do you have any recommends for this issue?
Public API Changes
Intended Use-Case
In my app, I have a VerticalStackLayout inside a ScrollView. The StackLayout has background is Black, so I cannot show the ScrollBar with default color.
Beta Was this translation helpful? Give feedback.
All reactions