Closed nuudles closed 5 years ago
Interesting. Do you have a sample project that can reproduce this? If not, I'll try to put one together when I have time.
A few easy things for debugging:
And secondarily: Are you setting the font using .font = …
or setting the NSFontAttributeName
on the attributed string? If you flip which one you're doing, does it work?
I've tried using both the .font
and the NSFontAttributeName
and variations of either or. It seems to work fine if I just don't set the font.
The frame looks fine here:
<ZSWTappableLabel: 0x7fbda1cdad00; baseClass = UILabel; frame = (12 345; 351 34);
Also interestingly enough if I manually set the height of the label instead of relying on Auto Layout and the intrinsic content size, it can detect the taps just fine, even with the custom font.
I think I'm having the same problem or at least a related problem. For me the last line in the label is not clickable.
When the text is too long for one line I call sizeToFit. If I call sizeToFit when there is only one line I can't register taps. If I don't call sizeToFit when there is only one line the taps work as expected.
I've created a gist with a slightly modified (not the real list of users) the code I use to create the label.
https://gist.github.com/Qw4z1/bfdbfd73055d41bf71bf8f4a30a76984
Thanks for the sample code, I'll take a look and see if I can figure out what's happening. It's possible non-integral frames are confusing the size of the container I'm creating for the text (to simulate locations).
I do not believe this occurs anymore.
Hey @zacwest! I'm trying to use your component to detect taps in my
NSAttributedString
, but I'm using a custom font and it seems like the detected touch area is sitting lower than it should be. I was able to verify this in the Example project by modifying the optionsbaseAttributes
in theMultipleSwiftViewController
like so:Interestingly enough this didn't reproduce the issue, however if the label is set to auto size the height instead of being matching the view's edges, I'm seeing the tap area be about 5-10 pts too low: