Truncate tail of a line in swift

1

I'm doing an example that shows me the tweets that there are according to the user who writes.

The problem is that by putting the Nombre de usuario and followed the nombre la cuenta % I% truncates the start of nombre de usuario instead of truncating the nombre de la cuenta . I explain it better with examples:

That's how it is now:

And that's how I want this to be:

EDITED

The first label , the typeface is System Bold 18.0 , set to a line

The second label , the typeface is System 13.0 , set to a line

I have made the images with paint , so the sizes and fonts may not correspond to the reality

    
asked by Ivan Botero 27.09.2016 в 08:46
source

1 answer

0

As I said, I think the best option is to calculate what each uilabel will occupy and from there change the frame and manually truncate the piece of text you want. The size that occupies what you get with that: (is in objC)

CGSize textSize = [label.text sizeWithAttributes:@{NSFontAttributeName:[label font]}];

And if you know how much room you have left, then you do a little math. To change a frame, what you have to do is remove it, change it and assign it:

CGRect fr = self.etiqueta.frame;
fr = CGRectMake(x, y, width, height);
self.etiqueta.frame = fr;

the values of x, y, width and height you have to calculate them depending on the size that you have on the screen

    
answered by 27.09.2016 / 21:39
source