UItextView + Slider

Discussion in 'iOS Programming' started by doudou974, Oct 16, 2009.

  1. macrumors newbie

    Joined:
    Oct 16, 2009
    Location:
    Paris
    #1
    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 ^^
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Oct 16, 2009
    Location:
    Paris
    #3
    thanks, but do you have an example or something, because I'm not really sure on how to do it.

    Thanks,
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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".
     
  5. thread starter macrumors newbie

    Joined:
    Oct 16, 2009
    Location:
    Paris
    #5
    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.)
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Lol, thanks for that :)

    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?
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Close, but as I suggested earlier, use UIFont's fontWithSize: instance method rather than it's fontWithName:size: class method.
     
  8. thread starter macrumors newbie

    Joined:
    Oct 16, 2009
    Location:
    Paris
    #8
    Thank you its working now with your advice.
    Subject close ^^
     

Share This Page