PDA

View Full Version : UItextView + Slider




doudou974
Oct 16, 2009, 08:59 AM
Hi,

I have a question for everyone. I have a TextView who contain some text of course. I also have a slider under that textView, and I would like to use it to change the size of the text inside the TextView. :confused:

Have some idea on How to do it? somes clues?

Thanks ^^



dejo
Oct 16, 2009, 09:46 AM
Use the value of the slider as the parameter in a call to the UIFont instance method fontWithSize: with your textView's font as the receiver.

doudou974
Oct 17, 2009, 04:44 AM
thanks, but do you have an example or something, because I'm not really sure on how to do it.

Thanks,

dejo
Oct 17, 2009, 01:21 PM
Well, take a stab at it. Post your code snippet here and we can guide you in the right direction. This should be, depending on how your UISlider is defined, possible with one line of code. Sorry, but I'm not prone to just give you the answer. Because, as robbieduncan likes to say, "copying and pasting code is not programming".

doudou974
Oct 18, 2009, 10:21 AM
ok the weekend is finish its time to go back in the objective-c, and yes
you're right copying and pasting code is not programming ::)



- (IBAction)sliderChanged:(id)sender
{
float sliderValue = (float)sliderSize.value;

textValue.text = [NSString stringWithFormat: @"%.0f", sliderSize.value];

textView.font = [UIFont fontWithName: nil size: sliderValue];

}

I begin like that. But I'm still missing something, the font size is still not changing with the value of the slider. Idea?
(textValue is only a label who return the value of the slider is not important here.)

robbieduncan
Oct 18, 2009, 10:43 AM
Because, as robbieduncan likes to say, "copying and pasting code is not programming".

Lol, thanks for that :)


- (IBAction)sliderChanged:(id)sender
{
float sliderValue = (float)sliderSize.value;

textValue.text = [NSString stringWithFormat: @"%.0f", sliderSize.value];

textView.font = [UIFont fontWithName: nil size: sliderValue];

}

Check that your call to UIFont is actually returning a non-nil object. I'd imagine (but I've not checked) that if you supply nil for the name you'll get nil back. Can you not get the font from the text view via the property you have used above and either alter the size of that or at least get the name from it to use?

dejo
Oct 18, 2009, 08:17 PM
textView.font = [UIFont fontWithName: nil size: sliderValue];
Close, but as I suggested earlier, use UIFont's fontWithSize: instance method rather than it's fontWithName:size: class method.

doudou974
Oct 18, 2009, 08:48 PM
Thank you its working now with your advice.
Subject close ^^