Giter VIP home page Giter VIP logo

efautoscrolllabel's Introduction

A label which can scroll when text length beyond the width of label, in Swift.

中文介绍

Overview

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Version Needs
1.x XCode 8.0+
Swift 3.0+
iOS 8.0+
4.x XCode 9.0+
Swift 4.0+
iOS 8.0+
5.x XCode 10.2+
Swift 5.0+
iOS 8.0+

Installation

CocoaPods

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

pod "EFAutoScrollLabel"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFAutoScrollLabel as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/EFPrefix/EFAutoScrollLabel.git", .upToNextMinor(from: "5.1.3"))
]

Setup

Simply initialize a EFAutoScrollLabel the same way you set up a regular UILabel:

let myLabel = EFAutoScrollLabel(frame: CGRect(x: 10, y: 10, width: 200, height: 40))
self.view.addSubview(myLabel)

Use

1. Import EFAutoScrollLabel module where you want to use it:

import EFAutoScrollLabel

2. Initialize a EFAutoScrollLabel and set some parameter:

let myLabel = EFAutoScrollLabel(frame: CGRect(x: 10, y: 10, width: 200, height: 40))
myLabel.backgroundColor = UIColor(red: 253.0 / 255.0, green: 255.0 / 255.0, blue: 234.0 / 255.0, alpha: 1)
myLabel.textColor = UIColor(red: 249.0 / 255.0, green: 94.0 / 255.0, blue: 22.0 / 255.0, alpha: 1)
myLabel.font = UIFont.systemFont(ofSize: 13)
myLabel.labelSpacing = 30                       // Distance between start and end labels
myLabel.pauseInterval = 1.7                     // Seconds of pause before scrolling starts again
myLabel.scrollSpeed = 30                        // Pixels per second
myLabel.textAlignment = NSTextAlignment.left    // Centers text when no auto-scrolling is applied
myLabel.fadeLength = 12                         // Length of the left and right edge fade, 0 to disable
myLabel.scrollDirection = EFAutoScrollDirection.left
self.view.addSubview(myLabel)

3. AutoLayout is also supported.

PS

The first version of EFAutoScrollLabel is converted from AutoScrollLabel.

Apps using EFAutoScrollLabel

Author

EyreFree, [email protected]

License

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

efautoscrolllabel's People

Contributors

eyrefree avatar

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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

efautoscrolllabel's Issues

UI API called on a background thread

After few ten seconds it stops to scroll and XCode says UI API called on a background thread: (the log below), also XCode highilghts these 3 issues. How to heal it? I put the func to DispatchQueue.main.async, it works, but don't think it is good.

ps. thanks for your work!

cropimage

Main Thread Checker: UI API called on a background thread: -[UILabel text]
PID: 2019, TID: 3478103, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApp!                          0x0000000100672f48 _T010MyAppO_17EFAutoScrollLabelC4textSSSgfg + 132
5   MyApp!                          0x0000000100676d08 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyF + 84
6   MyApp!                          0x0000000100677f08 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyFTo + 40
7   Foundation                          0x0000000187f93860 <redacted+ 996
8   libsystem_pthread.dylib             0x00000001871d032c <redacted+ 308
9   libsystem_pthread.dylib             0x00000001871d01f8 <redacted+ 0
10  libsystem_pthread.dylib             0x00000001871cec38 thread_start + 4

Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 2019, TID: 3478103, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApp!                          0x0000000100676fb4 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyF + 768
5   MyApp!                          0x0000000100677f08 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyFTo + 40
6   Foundation                          0x0000000187f93860 <redacted+ 996
7   libsystem_pthread.dylib             0x00000001871d032c <redacted+ 308
8   libsystem_pthread.dylib             0x00000001871d01f8 <redacted+ 0
9   libsystem_pthread.dylib             0x00000001871cec38 thread_start + 4

Main Thread Checker: UI API called on a background thread: -[UIView layer]
PID: 2019, TID: 3478103, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApp!                          0x0000000100677434 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyF + 1920
5   MyApp!                          0x0000000100677f08 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyFTo + 40
6   Foundation                          0x0000000187f93860 <redacted+ 996
7   libsystem_pthread.dylib             0x00000001871d032c <redacted+ 308
8   libsystem_pthread.dylib             0x00000001871d01f8 <redacted+ 0
9   libsystem_pthread.dylib             0x00000001871cec38 thread_start + 4

Main Thread Checker: UI API called on a background thread: -[UIScrollView setContentOffset:]
PID: 2019, TID: 3478103, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApp!                          0x0000000100677620 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyF + 2412
5   MyApp!                          0x0000000100677f08 _T010MyAppO_17EFAutoScrollLabelC06scrollE8IfNeededyyFTo + 40
6   Foundation                          0x0000000187f93860 <redacted+ 996
7   libsystem_pthread.dylib             0x00000001871d032c <redacted+ 308
8   libsystem_pthread.dylib             0x00000001871d01f8 <redacted+ 0
9   libsystem_pthread.dylib             0x00000001871cec38 thread_start + 4

Main Thread Checker: UI API called on a background thread:

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

The error appears.

Main Thread Checker: UI API called on a background thread: -[UILabel text]
PID: 6718, TID: 54018, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21

Description

It causes by this code.

    @objc public func scrollLabelIfNeeded() {
        if text == nil || text?.isEmpty == true {
            return
        }

        DispatchQueue.main.async { [weak self] in
            guard let self = self else { return }
            self.scrollLabelIfNeededAction()
        }
    }

Reproduce

I've got it by adding label to UIPickerView as custom view. If I do nothing for about 10 seconds the error appears.

Other Comment

This code fixed it.

    @objc public func scrollLabelIfNeeded() {
        DispatchQueue.main.async { [weak self] in
            guard let self = self else { return }
            if self.text == nil || self.text?.isEmpty == true {
                return
            }
            self.scrollLabelIfNeededAction()
        }
    }

XCode Warning: 'characters' is deprecated: Please use String or Substring directly

As of XCode 9.1, the following warning is issued:

'characters' is deprecated: Please use String or Substring directly -> EFTAutoScrollLabel.swift

XCode: 9.4
EFAutoScrollLabel: 4.0.2
Swift: 3.3

It would be great to take care of this to reduce the warnings in the build log. It is a very simple fix, I can submit a PR if you would like.

Thanks!

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.