How would I make the source text of a UITextView change whenever I press different buttons? Thanks.
Asked
Active
Viewed 2,582 times
2 Answers
3
To change the text of a UITextView
, set its text
property:
textView.text = @"your text here";
You can call this from within a button's selector like so:
UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[yourButton setTitle:@"click to change textview's text" forState:UIControlStateNormal];
[yourButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
...
- (void)buttonClicked:(id)sender {
textView.text = @"your text";
}

Mutix
- 4,196
- 1
- 27
- 39
-
How can I change the text without changing the font and properties? – Albert Català Nov 06 '13 at 18:54
-
@AlbertCatalà: You are probably running into this bug: http://stackoverflow.com/questions/19049917/uitextview-font-is-being-reset-after-settext – Bjorn Roche Jan 01 '14 at 19:02
0
just create different methods which changes the UITextView values. Connect it the correct way in IB to the textView and you're done.

Foo
- 596
- 2
- 5
- 21