Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

doudou974

macrumors newbie
Original poster
Oct 16, 2009
7
0
Paris
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 ^^
 
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.
 
thanks, but do you have an example or something, because I'm not really sure on how to do it.

Thanks,
 
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".
 
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 ::)

Code:
- (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.)
 
Because, as robbieduncan likes to say, "copying and pasting code is not programming".

Lol, thanks for that :)

Code:
- (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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.