hsusmita / ResponsiveLabel

MIT License
218 stars 36 forks source link

Truncation token set from interface builder does not show #9

Closed Mackarous closed 9 years ago

Mackarous commented 9 years ago

I am trying to set the truncation token in IB, but I do not have width/height constraints. I have top, bottom, left, right constraints instead. The UILabel is set to be a ResponsiveLabel, number of lines = 0.

The token shows in IB, but not when the app runs

Any ideas?

hsusmita commented 9 years ago

@Mackarous Have you given preferred width?

hsusmita commented 9 years ago

@Mackarous I figured out the issue. I need some more time to fix this. For the time being, you can programmatically set the truncation token.

Mackarous commented 9 years ago

@hsusmita I have a preferred width, and I attempted to set the truncation token programatically also but it still doesn't work.

hsusmita commented 9 years ago

@Mackarous Does it show default ellipse?

Mackarous commented 9 years ago

Yes it does

hsusmita commented 9 years ago

@Mackarous Is there any error regarding IBDesignable?

Mackarous commented 9 years ago

No error for IBDesignable at all

hsusmita commented 9 years ago

@Mackarous, I am unable to diagnose the issue. It should work programmatically. Can you share sample code on github? It would be helpful in understanding the issue.

Mackarous commented 9 years ago

Sure. I simply add a label to my storyboard. The label has top, bottom, left, and right constraints. No height or width constraints. It has numberOfLines = 5, and I add too much text so it must truncate. I then use the following lines of code:

let token = "... More"
let attributedString = NSMutableAttributedString(string: token, attributes: [NSFontAttributeName : self.label.font])
self.label.setAttributedTruncationToken(attributedString, withAction: { tappedString in
    println("hit")
})
self.label.setText(self.labelText, withTruncation: true)
hsusmita commented 9 years ago

@Mackarous Updated library. Try latest version, i.e 1.0.4 and let me know if there is still any issue. FYI, I will be releasing swift implementation of ResponsiveLabel by the end of this week.

Mackarous commented 9 years ago

@hsusmita Thank you! It works perfectly now! Great work. Also just wondering if you are planning on putting hit state on the truncation token?

hsusmita commented 9 years ago

@Mackarous What do you mean by hit state? Is it something like highlighting the token on tap?

Mackarous commented 9 years ago

@hsusmita yes exactly

hsusmita commented 9 years ago

@Mackarous The bug in highlighting token is fixed. Check the version 1.0.5. Here is the sample code is

 let token = "... Read More"
 let attributedString = NSMutableAttributedString(string: token, attributes: [NSFontAttributeName : self.label.font
   ,RLHighlightedBackgroundColorAttributeName:UIColor.blackColor(),RLHighlightedForegroundColorAttributeName:UIColor.greenColor(),NSForegroundColorAttributeName:UIColor.redColor()])

    self.label.setAttributedTruncationToken(attributedString, withAction: { tappedString in
      println("hit")
    })

self.label.setText(self.labelText, withTruncation: true)
Mackarous commented 9 years ago

Perfect! Thank you so much!