Giter Site home page Giter Site logo

expandablelabel's People

Contributors

beiliubei avatar czgarrett avatar diva-e-wiedemann avatar elegyd avatar justinctlam avatar levantaj avatar lj-dickey avatar michaelkamphausen avatar mkoehnke avatar sammy-sc avatar samukei avatar tachtevrenidis avatar tinora 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

expandablelabel's Issues

Behaves strange when used as the detailTextLabel

I have specified the detailTextLabel in a UITableViewCell to be an ExpandableLabel. The layout of the expandable label is not working very well. When the table is first loaded it shows only a few characters of the label text and no "...More" link. When scrolling down a little so the cell is no longer visible and then scrolling back up the expandable label is shown correctly. I'm pulling my hair out to figure out how I can trigger the expandable label to do its layout correctly the first time. It can also act strange... sometimes putting the ...More link too early in the text. And then after scrolling a few times more it can all of a sudden be correct again. I'm calling cell.layoutIfNeeded() after the text is set but it doesn't help.

Close button not working

Close button is not Working and one more Thing in delegate method for ...More I want to reload a particular cell not the entire tableView

Read More added in the first line

Read More added in the first line , but my condition was to add it after the 3rd line.
This happens after you only reload 1 cell in the table view , then the next cell after that automatically shows "read more" for 1 line text only.

Support for Swift 4

Does this project support swift 4? If not, when do you think you will have a version for swift 4 available?

Supporting RTL languages

The expandableLabel's textAlignment is always .left without referring textAlignment property.

I've set it to .Right or .Natural, but the label shows the text always as .Left

Please help me solve this issue.

Not working for some cells

Strangely it does not work in some cells. It shows the text, and it's truncated correctly, but there is no "More" to click to expand the text. It's get more strange since the problem gets fixed when I go to another view (page) and then back to the table.

Emoji and Special characters

Label crashes when setting strings like this:
"╭┈┈┈┈╯   ╰┈┈┈╮\n\n ╰┳┳╯    ╰┳┳╯\n   💧     💧\n\n "

Not working in iOS 11

I am having issues implementing this in my VC in iOS 11. Do you know if there are any issues when using this project in iOS 11? I have the expandable label in a scrollview not a tableview like in the demo.

Custom Font Issue

Hi There,

Thanks for creating this awesome control !

I am facing a wired issue in this. If I set custom font in expandable label its is not working it is only working in system font.

Can you plz help me in this?

Thanks in again
Hoping for positive and the quick reply.

Tapping label does nothing

If an Expandable Label is in a tableview cell and a user taps the Expandable Label, "didselectrow" at index path is not called. It does not allow us to select a cell if a user taps on the Expandable Label within that cell.

Xcode 10.2 with Swift 5

Hi ,

Expandable Label is not compiling with Xcode 10.2 which has Swift 5 Version.

Please update this to Swift 5.

Delegate function not being called

The functions willExpandLabel, didExpandLabel, etc are not being called.

I added ExpandableLabelDelegate to my controller class and label.delegate = self on the ExpandableLabel.

Any solution?

Play nicely with AutoLayout

Noticed this when I constructed my components programmatically - the label doesn't handle size changes.

Now on each size change (width change as it were) the calculations need to be redone

I would create a PR but I think it would be best to change the component for that - the main point is that the original text needs to be stored somewhere, otherwise we can't redo the calculations.

I made the following changes to make it work

USAGE CHANGE: set the fullText var instead of either text or attributedText

expandedLabel.fullText = NSAttributedString(string: "Something")

Add the following method / var to class ExpandedLabel

....
    open var fullText: NSAttributedString?
....
    override open func layoutSubviews() {
        super.layoutSubviews()
        self.attributedText = fullText
    }

This way, I can create the component programatically and lay it out before it's ever shown on screen and it will work

Also, if the layout changes for some other reason, it's also going to work.

Tested, works fine so far

"Read more" button appear in the middle of the line

"Read more" button appear in the middle of the line and after a couple of reloadData its appears at the correct position (toward the end of the line). I tried layoutIfNeeded and settign the width of the label before setting the text but nothing is working.
Any ideas?

Crash

File ExpandableLabel.swift
line 140

    open override var text: String? {
        set(text) {
            if let text = text {
                expandedText = getExpandedTextForText(text, link: expandedAttributedLink)?.copyWithAddedFontAttribute(font)
                self.attributedText = NSAttributedString(string: text)
            } else {
                self.attributedText = nil
            }
        }
        get {
            return self.attributedText?.string
        }
    }

Will crash if set empty string - ""

Error with setLessLinkWith

I am getting an error "is inaccessible due to internal protection level" when trying to access the method setLessLinkWith. Did you not make this public?

Programatically added label does not expand

When I add ExpandedLabel programatically as sub view then it does not detect proper touch coordinate.
label = ExpandableLabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: CGFloat.leastNormalMagnitude))

    label?.collapsed = true
    label?.shouldCollapse = true
    label?.textReplacementType = .character
    label?.setLessLinkWith(lessLink: "Show Less", attributes: [.foregroundColor:UIColor.red], position: .natural)
    label?.collapsedAttributedLink = NSAttributedString(string: "Show More", attributes: [.font: UIFont.boldSystemFont(ofSize: (label?.font.pointSize)!)])
    label?.numberOfLines = 1
    view.addSubview(label!)
    
    label?.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint(item: label!, attribute: NSLayoutAttribute.leadingMargin, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.leadingMargin, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: label!, attribute: NSLayoutAttribute.trailingMargin, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.trailingMargin, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: label!, attribute: NSLayoutAttribute.topMargin, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.topMargin, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: label!, attribute: NSLayoutAttribute.bottomMargin, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.bottomMargin, multiplier: 1, constant: 0).isActive = true
    
    
    label?.text = "Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test "`

Using expandedAttributedLink does not work

When I use either of these two lines of code, the field does not collapse. This is just a normal VC not a tableview cell. It will expand but it will not collapse.

descriptionLabel.expandedAttributedLink = NSAttributedString(string: "show less",attributes: [ NSForegroundColorAttributeName: UIColor( red: 42/255, green: 91/255, blue:140/255, alpha: 1 ), NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])

descriptionLabel.setLessLinkWith(lessLink: "show less", attributes: [NSForegroundColorAttributeName: UIColor( red: 42/255, green: 91/255, blue:140/255, alpha: 1 ), NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)], position: nil)

Delegate

I know the demo is working, but in my code, when I write mCell.expandablelabel.delegate=self, and add delegate functions at the end, it seems it doesn't fire the delegate function when I tap on "read more". I tested it by print("test") in the methods.
PS: I converted my app from Swift 3.2 to 4 to work with this pod. My app worked with Swift 3 version of this pod before.

Does not works with iPhone 5s

Hi
Read more does not comes at first load, after scrolling it appears this problem only occurs in iPhone 5s and below.
Also the last item get automatically collapsed on expanding it.
How can i solve this pls help.

Thanks

Swift 3

Hey,

Any plan to support Swift 3.0?

Bests

Swift 4 issue

The pod does not compile for swift 4 for attribute name keys

screen shot 2017-10-06 at 3 18 19 pm

label cannot expand when text is chinese word ?

    @IBOutlet weak var label: ExpandableLabel!
    @IBOutlet weak var labelForChinese: ExpandableLabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        [self.label,self.labelForChinese].forEach { (xxlable) in
            xxlable?.numberOfLines = 3
            xxlable?.collapsed = true
            xxlable?.backgroundColor = UIColor.lightGray
            xxlable?.collapsedAttributedLink = NSAttributedString(string: "[Show More]")
            xxlable?.expandedAttributedLink = NSAttributedString(string: "[Show Less]")
            xxlable?.shouldCollapse = true
        }
        
        
        self.label.text = "On third line our text need be collapsed because we have ordinary text, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
        
        self.labelForChinese.text = "中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文文中文中文中文"

    }

2018061227808st.png

Swift 4.2 released?

a couple of days ago, I sent a PR that upgrades the code to Swift 4.2 and it was merged by @tinora (thanks!). Can you guys release this? I need to pull it into my lib :-)

collapsedAttributedLink & expandedAttributedLink issue

Hi,
collapsedAttributedLink is not shown when i set number of line for label to 1 and expandedAttributedLink is not showing always. On tab of label expand and shrink is working but collapsedAttributedLink and expandedAttributedLink text is not shown. I have tried the same demo from github in that also it is not displaying. I have tried setLessLinkWith also.

Wrong collapsed text when setting a NSAttributedString using both HTML and "regular" attributes.

Hi there,

I'm setting my attributed string the following way:

let fontFamily = "font-family: \(fontName);"
let fontSize = "font-size: \(fontSize);"
let color = "color: \(htmlRGBColor);"
let htmlString = "<p style=\"\(fontFamily) \(fontSize) \(color)\">\(self)</p>"

let attributedString = try! NSMutableAttributedString(
    data: htmlString.dataUsingEncoding(NSUTF16StringEncoding)!,
    options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],
    documentAttributes: nil)

if let paragraphStyle = aParagraphStyle {
    attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
}

For some reason, when I set the text alignement and the line spacing through the additional paragraph style attribute, bot the collapsedAttributedLink and the ellipsis are not displayed anymore.

I observed that getCollapsedTextForText() consistently returns the expanded text (instead of the collapsed one) and I supsect it is because, in this case, linesForWidth(_ :) always returns a a wrong array of CTLinesRef, but I'm struggling to go forward in the debugging.

Any idea?

Thank you for your help!

UPDATE :
A workaround for the specific line-height issue (one of the variables I set on my NSParagraphStyle) is to set it via HTML styles.

However, I cannot set the text alignement using the same technique as the text-align property is exclusively available with block tags and a bug in iOS (libxml?) prevents me from doing so as it adds an unwanted extra space at the bottom of the string (see this issue)

Hence, being able to add most of the attributes via the addAttributed:value:range method would be really convenient 😄

see less feature

I have just one expandableLabel and the 'see more" function works perfectly. Is it possible to add a "see less" function now that will return the label to its original state?

CLOSE added to all cells in a tableView

I use the ExpandableLabel in a tableview, when I press on MORE in one of the CELL then all my cells have the red CLOSE in them, even those that didn't need to expand

Objective C doesn't see label delegate property and protocol definition

There are @objc declarations missing for delegate property and for protocol declaration in the library, and therefore Objective-C doesn't see this property at all and can't be used within Obj-C project. Please include this fix in your next release (add @objc before the delegate property and before protocol). Would be a good idea to create sample project in Objective-C just to be sure everything written is Swift is accessible from objective-c. It might also be a good idea to make all those delegate methods optional, so developers can decide which one is needed, and not include all 4 just to use a single one in the project.

Height Becomes 0 When Putting Label Inside StackView

Hello,

I was using ExpandableLabel on a vertical StackView with these configurations :

  • Alignment Fill
  • Distribution Fill

I just changed these ExpandableLabel properties through storyboard :

  • Collapsed On
  • Text bla bla bla
  • Lines 3

When I ran the app, the label shows nothing.
Do you have any suggestions?

Thanks!

Causing memory leaks

A leak is being produced when an instance of ExpandableLabel is allocated on memory.

For instance, if an ExpandableLabel is added to a UITableViewCell, when using instruments one can perceive that such cells are causing memory issues as elements persist even after deallocation of cells.

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.