Search code examples
iphoneiosxcodeuitableviewcgrect

Add some text to particular area in UITextView programmatically?


I create an instance of UITextView programmatically. I want to add some text to particular area in UITextView programmatically. Here is my code to create UITextView.

      UITextView *textView =[[UITextView alloc]init];
      textView.frame=CGRectMake(0,0,282,210);
      [textView setReturnKeyType:UIReturnKeyDone];
      [self.view addSubview:textView];

For example I want to add some text to particular Area CGRectMake(260,190,20,20). Then add this text to UITextView. Programmatically, please any one guide me, how is it possible to do this?


Solution

  • You could add an UILabel there.

    UITextView *textView = [[UITextView alloc] init];
    TextView.frame = CGRectMake(0.0,0.0,282.0,210.0);
    [textView setReturnKeyType: UIReturnKeyDone];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(260.0,190.0,20.0,20.0);
    label.text = @"T"; //here you set the text you want...
    
    [textView.view addSubview: label];
    
    [self.view addSubview: textView];