Resize text in UIButton

The client wants me to do something, I just checked, and I am sure that this is not possible. He asked to put the text on the button (UIButton). (Default state configuration) And when the user clicks on it, the text should be enlarged. (High Status Configuration) I checked by selecting Highligted State Configuration and then resized the text in Interface Builder, but I did not work. The text has also changed for the default configuration. Please tell me if there is a way to do this.

Thank!

Teymur

+5
source share
3 answers

, IB, . , . , ( , ).

- (IBAction)buttonDown:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
}

- (IBAction)buttonUp:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.titleLabel.font = [UIFont boldSystemFontOfSize:15.0];
}
+10
  btn.titleLabel.adjustsFontSizeToFitWidth = TRUE;

...

+7

. IBActions , onTouchDown onTouchUp. IBOutlet . Interface Builder IBOutlet "Touch Down" "onTouchDown" "Touch Up Inside" "Touch Up Outside" "onTouchUp".

onTouchDown - , . onTouchUp - reset .

:

@interface TestViewController : UIViewController {
    UIButton *testButton;
}


@property (nonatomic, retain) IBOutlet UIButton *testButton;
- (IBAction)onTouchDown;
- (IBAction)onTouchUp;

, onTouchDown, :

1)

2)

3) ( )

4)

, :

- (IBAction)onTouchDown:(id)sender
{
    CGRect oldBtnRect = testButton.frame;
    testButton.titleLabel.font = [UIFont systemFontOfSize:36];
    [testButton sizeToFit];
    testButton.frame = CGRectMake(testButton.frame.origin.x - ((testButton.frame.size.width - oldBtnRect.size.width)/2), testButton.frame.origin.y - ((testButton.frame.size.height - oldBtnRect.size.height)/2), testButton.frame.size.width, testButton.frame.size.height);
}

: 36.

:

- (IBAction)onTouchUp:(id)sender
{
    CGRect oldBtnRect = testButton.frame;
    testButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [testButton sizeToFit];
    testButton.frame = CGRectMake(testButton.frame.origin.x - ((testButton.frame.size.width - oldBtnRect.size.width)/2), testButton.frame.origin.y - ((testButton.frame.size.height - oldBtnRect.size.height)/2), testButton.frame.size.width, testButton.frame.size.height);
}

. 15.

, , .

. , . , , , . ;)

+1

All Articles