Giter Club home page Giter Club logo

dmscrollbar's Introduction

DMScrollBar

CI Status Version License Platform

Example

iOS style Default style iOS & Default combined style Absolutely custom style Right label style Easy to change

Description

DMScrollBar is best in class customizable ScrollBar for ScrollView. It has:

  • Showing info label when user interaction with ScrollBar is started
  • Decelerating, Bounce & Rubber band mechanisms
  • Super customizable configuration
  • Different states for active / inactive states
  • Haptic feedback on interaction start / end and when info label changes on specified offset
  • Super Fancy animations

Installation

DMScrollBar is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DMScrollBar', '~> 1.0.0'

and run

pod install

Usage

On any ScrollView you want to add the ScrollBar with default configuration, just call (see result on Gid #2):

scrollView.configureScrollBar()

If you want to provide title for info label, implement DMScrollBarDelegate protocol on your ViewController:

extension ViewController: DMScrollBarDelegate {
    /// In this example, this method returns the section header title for the top visible section
    func indicatorTitle(forOffset offset: CGFloat) -> String? {
        return "Your title for info label"
    }
}

If you want to have iOS style scroll bar, configure ScrollBar with .iosStyle config (Next code will create config for the Scroll Bar for Gif #1):

scrollView.configureScrollBar(with: .iosStyle, delegate: self)

Any ScrollBar configuration can be easily combined with another one (Next code will create config for the Scroll Bar for Gif #3):

let iosCombinedDefaultConfig = DMScrollBar.Configuration(
    indicator: .init(
        normalState: .iosStyle(width: 3),
        activeState: .default
    )
)
scrollView.configureScrollBar(with: iosCombinedDefaultConfig, delegate: self)

If you want to configure scroll bar, with custom config, create configuration and call configureScrollBar (Next code will create config for the Scroll Bar for Gif #4):

let customConfig = DMScrollBar.Configuration(
    isAlwaysVisible: false,
    hideTimeInterval: 1.5,
    shouldDecelerate: false,
    indicator: DMScrollBar.Configuration.Indicator(
        normalState: .init(
            size: CGSize(width: 35, height: 35),
            backgroundColor: UIColor(red: 200 / 255, green: 150 / 255, blue: 80 / 255, alpha: 1),
            insets: UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0),
            image: UIImage(systemName: "arrow.up.and.down.circle")?.withRenderingMode(.alwaysOriginal).withTintColor(UIColor.white),
            imageSize: CGSize(width: 20, height: 20),
            roundedCorners: .roundedLeftCorners
        ),
        activeState: .custom(
            config: .init(
                size: CGSize(width: 50, height: 50),
                backgroundColor: UIColor.brown,
                insets: UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 6),
                image: UIImage(systemName: "calendar.circle")?.withRenderingMode(.alwaysOriginal).withTintColor(UIColor.cyan),
                imageSize: CGSize(width: 28, height: 28),
                roundedCorners: .allRounded
            ),
            textConfig: nil
        ),
        stateChangeAnimationDuration: 0.5,
        insetsFollowsSafeArea: true,
        animation: .init(showDuration: 0.75, hideDuration: 0.75, animationType: .fadeAndSide)
    ),
    infoLabel: DMScrollBar.Configuration.InfoLabel(
        font: .systemFont(ofSize: 15),
        textColor: .white,
        distanceToScrollIndicator: 40,
        backgroundColor: .brown,
        textInsets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8),
        maximumWidth: 300,
        roundedCorners: .init(radius: .rounded, corners: [.topLeft, .bottomRight]),
        animation: .init(showDuration: 0.75, hideDuration: 0.75, animationType: .fadeAndSide)
    )
)
scrollView.configureScrollBar(with: customConfig, delegate: self)

Author

Dmitrii Medvedev, [email protected]

License

DMScrollBar is available under the MIT license. See the LICENSE file for more info.

dmscrollbar's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dmscrollbar's Issues

Crash.

Tried pod on the test project to understand if I can use it in production. But it crashes on launch. Logs:

2023-06-02 12:39:48.058575+0300 testZoomAndScroll[89321:6369995] *** Assertion failure in -[NSLayoutConstraint _setSymbolicConstant:constant:symbolicConstantMultiplier:], NSLayoutConstraint.m:669
2023-06-02 12:39:48.077840+0300 testZoomAndScroll[89321:6369995] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSLayoutConstraint constant is not finite!  That's illegal.  constant:nan firstAnchor:<NSLayoutYAxisAnchor:0x600002a18f00 "UIView:0x15b10ccf0.top"> secondAnchor:<NSLayoutYAxisAnchor:0x600002a18ac0 "DMScrollBar.DMScrollBar:0x15b10c940.top">'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000180437330 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180051274 objc_exception_throw + 56
	2   Foundation                          0x0000000180ae29b4 _userInfoForFileAndLine + 0
	3   CoreAutoLayout                      0x00000001a857a1ac -[NSLayoutConstraint _setSymbolicConstant:constant:symbolicConstantMultiplier:] + 524
	4   CoreAutoLayout                      0x00000001a857a43c -[NSLayoutConstraint setConstant:] + 92
	5   CoreAutoLayout                      0x00000001a857e094 +[NSLayoutConstraint constraintWithAnchor:relatedBy:toAnchor:multiplier:constant:] + 240
	6   DMScrollBar                         0x00000001029032f4 $s11DMScrollBarAAC5setup33_BF412082A14CCD2DECDFFE1FEE065EF0LL11stateConfigyAB13ConfigurationV9IndicatorV05StateK0V_tF + 1792
	7   DMScrollBar                         0x0000000102902bcc $s11DMScrollBarAAC20setupScrollIndicator33_BF412082A14CCD2DECDFFE1FEE065EF0LLyyF + 708
	8   DMScrollBar                         0x0000000102901cf4 $s11DMScrollBarAAC10scrollView8delegate13configurationABSo08UIScrollD0C_AA0aB8Delegate_pSgAB13ConfigurationVtcfc + 1388
	9   DMScrollBar                         0x0000000102901778 $s11DMScrollBarAAC10scrollView8delegate13configurationABSo08UIScrollD0C_AA0aB8Delegate_pSgAB13ConfigurationVtcfC + 64
	10  DMScrollBar                         0x00000001029241b8 $sSo12UIScrollViewC11DMScrollBarE015configureScrollD04with8delegateyA2CC13ConfigurationV_AC0cD8Delegate_pSgtF + 212
	11  testZoomAndScroll                   0x00000001023b5e94 $s17testZoomAndScroll14ViewControllerC015configureCustomdE033_5EDD3B2F749AEE651A9915552C6C14D4LLyyF + 876
	12  testZoomAndScroll                   0x00000001023b48b4 $s17testZoomAndScroll14ViewControllerC05setupE033_5EDD3B2F749AEE651A9915552C6C14D4LLyyF + 68
	13  testZoomAndScroll                   0x00000001023b4864 $s17testZoomAndScroll14ViewControllerC11viewDidLoadyyF + 88
	14  testZoomAndScroll                   0x00000001023b48e8 $s17testZoomAndScroll14ViewControllerC11viewDidLoadyyFTo + 36
	15  UIKitCore                           0x00000001095f8e64 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 80
	16  UIKitCore                           0x00000001095fcbc8 -[UIViewController loadViewIfRequired] + 708
	17  UIKitCore                           0x00000001095fceb4 -[UIViewController view] + 20
	18  UIKitCore                           0x0000000109cca8d4 -[UIWindow addRootViewControllerViewIfPossible] + 132
	19  UIKitCore                           0x0000000109cca310 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 212
	20  UIKitCore                           0x0000000109ccb150 -[UIWindow _setHidden:forced:] + 228
	21  UIKitCore                           0x0000000109cd9c18 -[UIWindow _mainQueue_makeKeyAndVisible] + 36
	22  UIKitCore                           0x0000000109ec5a50 -[UIWindowScene _performDeferredInitialWindowUpdateForConnection] + 204
	23  UIKitCore                           0x000000010925e868 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1096
	24  UIKitCore                           0x0000000109c943c8 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 880
	25  UIKitCore                           0x0000000109c94850 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 368
	26  UIKitCore                           0x00000001097f32a0 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
	27  FrontBoardServices                  0x0000000184e58bfc -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 316
	28  FrontBoardServices                  0x0000000184e7f638 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.61 + 92
	29  FrontBoardServices                  0x0000000184e64704 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
	30  FrontBoardServices                  0x0000000184e7f2dc __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 296
	31  libdispatch.dylib                   0x00000001025d5d50 _dispatch_client_callout + 16
	32  libdispatch.dylib                   0x00000001025d9968 _dispatch_block_invoke_direct + 392
	33  FrontBoardServices                  0x0000000184e9ef14 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
	34  FrontBoardServices                  0x0000000184e9ee08 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 176
	35  FrontBoardServices                  0x0000000184e9ef48 -[FBSSerialQueue _performNextFromRunLoopSource] + 24
	36  CoreFoundation                      0x000000018039ac6c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
	37  CoreFoundation                      0x000000018039abb4 __CFRunLoopDoSource0 + 172
	38  CoreFoundation                      0x000000018039a37c __CFRunLoopDoSources0 + 320
	39  CoreFoundation                      0x0000000180394958 __CFRunLoopRun + 748
	40  CoreFoundation                      0x0000000180394254 CFRunLoopRunSpecific + 584
	41  GraphicsServices                    0x0000000188eb7c9c GSEventRunModal + 160
	42  UIKitCore                           0x0000000109c92ff0 -[UIApplication _run] + 868
	43  UIKitCore                           0x0000000109c96f3c UIApplicationMain + 124
	44  libswiftUIKit.dylib                 0x0000000102cf4454 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100
	45  testZoomAndScroll                   0x00000001023b73c8 $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 120
	46  testZoomAndScroll                   0x00000001023b7344 $s17testZoomAndScroll11AppDelegateC5$mainyyFZ + 32
	47  testZoomAndScroll                   0x00000001023b7444 main + 28
	48  dyld                                0x00000001026b9514 start_sim + 20
	49  ???                                 0x000000010248df28 0x0 + 4333297448
	50  ???                                 0xb31d000000000000 0x0 + 12906472107113709568
)
libc++abi: terminating due to uncaught exception of type NSException

Can attach a test project if needed.

testZoomAndScroll.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.