2

Here is what I am trying to achieve. Instagram notification cell style:

enter image description here

I have a UIButton, and 2 UILabels, each with separate styles. They are currently all individual, but I want them to look like one string. So no matter how many line breaks, label 1 follows the end of the UIButton title, and wraps around it if multiple lines. And label 2 follows the end of label 1 no matter how many line breaks.

I have looked into attributed text strings, only I got stuck on keeping the first part (currently UIButton) actionable.

And then I looked into stack views. But for the life of me, I can't see how I could have the text wrap around UIButton title text.

Also worth noting all text is dynamic.

Can someone please help me understand the best approach for this?

I'm using Swift 2.2

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Dan
  • 543
  • 2
  • 13
  • You could have a look at `UITextView` instead of using `UILabels`. You can access the `textContainer` property and I believe you can add an `exclusionPath` from the button's frame to this to have the text wrap around it. Also, it the button just text? Or is there a button border etc... If it's just text you might want to just use attributed text and have a tappable region inside it? Not really clear on what you want to do here so not sure what the best approach is. – Fogmeister Oct 03 '16 at 10:04
  • This is hacky but if you get stuck you could use an attributed label to get the text with the grey time at the end and have the start of the label as the user's ID but cover that part with a button with a white background to cover any misalignment. – Ben Sullivan Oct 03 '16 at 10:13

0 Answers0