質問

I am using a stepper to control the font size of a text view, but there is no action being fired until I press the stepper twice. Why is this happening?

The following code is for the `mystepper' IBAction:

- (IBAction) changeFontSize:(id)sender
{

    [myStepper setMinimumValue:14.0]
    self.myStepper.maximumValue =20.0;

    UIFont newSize = [myTextView fontWithSize:self.stepper.value];
    self.myTextView.font = newSize;

}

I find the problem is that i need set the current value of stepper equals to minimumvalue. However, I want the value of size can pass through in muiltple scences so that the fontSize doesn't need to be press overtime. How can i get it???

役に立ちましたか?

解決

In viewDidLoad:

[myStepper setMinimumValue:14.0]
[myStepper setMaximumValue:20.0]

UIFont newSize = [myTextView fontWithSize:self.stepper.value]; // provide some default value to myStepper
self.myTextView.font = newSize;

// assign one method to stepper - value changed event

- (IBAction)stepperValueChanged:(id)sender
{
    double stepperValue = ourStepper.value;

    [self.myTextView setFont:[self.myTextView.font fontWithSize:stepperValue]];
}

This is the core logic, but there might be minor changes reuqire, to satisfy your requirement.

Hope this will help you.

他のヒント

As you want to set the size in multiple screens. So one practice would be to use userDefaults.

In your viewDidLoad method you need to read the userDefaults and check if there is no saved data for the same, save minValue and maxValue.

And in your method

- (IBAction)stepperValueChanged:(id)sender{
    double stepperValue = ourStepper.value;
   ...
}

use the new value and update the userDefaults value.

And fetch the userDefaults value and use that size throughout the application.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top