xcode 用于 UIScrollView 的 iOS 自定义滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17894330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:38:01  来源:igfitidea点击:

iOS custom scrollbar for UIScrollView

iosxcodeuiscrollviewuislider

提问by user2437310

iOS scrollbars for a UIScrollViewusually hide after a brief delay, but I want to the scrollbars in my app to show all the time like in this picture: Scrollbars visible all the time

iOS 滚动条UIScrollView通常在短暂延迟后隐藏,但我希望我的应用程序中的滚动条始终显示,如下图所示:滚动条始终可见

Do you have any Idea how to implement this feature? Can I use a custom UISlider for this? If you can provide answers, please do so in simple English because it's not my native language. Thank you!

您知道如何实现此功能吗?我可以为此使用自定义 UISlider 吗?如果你能提供答案,请用简单的英语回答,因为这不是我的母语。谢谢!

回答by user2258141

There is no direct way to show scrollbar permanent.

没有直接的方法可以永久显示滚动条。

You can do this by UISlider and UIImageView.

你可以通过 UISlider 和 UIImageView 来做到这一点。

1) Add UImage View for Vertical line.

1) 为垂直线添加 UImage 视图。

UIImageView *scrollLineImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scroll_1-1.png"]];
scrollLineImageView.frame = CGRectMake(970,160,2,254);
[self.view addSubview:scrollLineImageView];

2) Add UISlider and transform to UISlider vertical .UISlider height should be your scroll view height.

2) 添加 UISlider 并转换为 UISlider 垂直。UISlider 高度应该是您的滚动视图高度。

CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI * 0.5);
self.scrollViewSlider.transform = trans;
self.scrollViewSlider.frame = CGRectMake(972.5,189,0, self.textScrollView.frame.size.height);
Set Slider minimum value to 0 and maximum value to scrollView content height.
self.scrollViewSlider.minimumValue = 0.0;
self.scrollViewSlider.maximumValue = self.textScrollView.contentSize.height;

3) Set UISlider Thumb Image

3) 设置 UISlider 拇指图片

[self.scrollViewSlider setThumbImage:[UIImage imageNamed:@"scroll_circle.png"] forState:UIControlStateNormal];

4) Clear Minimum and Maximum track Image.

4) 清除最小和最大轨道图像。

UIImage *clearImage = [[UIImage alloc] init];
[self.scrollViewSlider setMinimumTrackImage:clearImage forState:UIControlStateNormal];
[self.scrollViewSlider setMaximumTrackImage:clearImage forState:UIControlStateNormal];

5) ScrollView Delegate Function to scroll slider

5) ScrollView 委托函数滚动滑块

self.scrollViewSlider.value=scrollView.contentOffset.y;

I hope this helps you to show Scroll Bar Permanent.

我希望这可以帮助您显示 Scroll Bar Permanent。