LightNight
LightNight

Reputation: 1625

How to make the carriage for UILabel

I need to make a view that will be changing a UILabel font-size (as on a picture below), for example when I touch right top corner and dragging to the top UILabel must changes it font-size.. please help me

enter image description here

Upvotes: 1

Views: 160

Answers (3)

LJ Wilson
LJ Wilson

Reputation: 14427

I am not sure exactly what you are wanting to do, but maybe this will get ya started:

Make sure you have a UILabel (I named mine myLabel) wired up correctly (User Interaction Enabled) must be checked) and then in the parent class:

In viewDidLoad:

UIPinchGestureRecognizer *recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self 
                                            action:@selector(twoFingerPinch:)];

[myLabel addGestureRecognizer:recognizer];

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer {
    //  Modify this to suit your needs
    if (recognizer.scale > 1.5) {
        self.myLabel.font = [UIFont systemFontOfSize:recognizer.scale *10];
    } else {
        self.myLabel.font = [UIFont systemFontOfSize:14];
    }
}

There are several different gesture recognizers out there and maybe tapGestureRecognizer might suit you better. This one will resize as the user pinches/zooms.

Upvotes: 1

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12949

If what you need is a resizable UIView. You can take a look at SPUserResizableView for iOS

Then, I'm sure that handling the size of a UILabel is done by setting the adjustsFontSizeToFitWidth property to YES like Adrian said.

Upvotes: 1

Adrian Schönig
Adrian Schönig

Reputation: 1786

I am not sure if I understand your question correctly. You can try setting the initial font size to a high value and myLabel.adjustsFontSizeToFitWidth = YES;. That way the font size will be automatically scaled down if the label is too small for the text the fit.

Upvotes: 1

Related Questions