How To Fix UITextView in storyboard TextView

229 Views Asked by At

Here i want to fix a UITextView which i created programatically in textView added on storyboard. I have tried it this way but not working.

_textView is a textView in which i have to fix UITextView *descrip

contentView is the view on which i have _textView.

  UITextView *descrip = [[UITextView alloc]init];

  descrip.view.frame = CGRectMake(_textView.frame.origin.x,_textView.frame.origin.y,_textView.frame.size.width,_textView.frame.size.height);

  [self.contentView addSubview:descrip.view];
3

There are 3 best solutions below

6
PinkeshGjr On BEST ANSWER

here is proper method

UITextView *descrip = [[UITextView alloc]initWithframe:CGRectMake(_textView.frame.origin.x,_textView.frame.origin.y,_textView.frame.size.width,_textView.frame.size.height)]
  [self.contentView addSubview:descrip];
17
Rohit Khandelwal On

You can do something like this--

UITextView *descrip = [[UITextView alloc]initWithFrame:_textView.frame];
[self.contentView addSubview:descrip];

there is no need to to use CGRectMake if you want to give same frame as _textView frame.

7
UdayM On

If I understood correctly, you are trying to add descrip into_textView; try this:

UITextView *descrip =[[UITextView alloc]initWithFrame:CGRectMake(0, 0, _textView.frame.size.width, _textView.frame.size.height)];
descrip.backgroundColor=[UIColor blueColor];
[self.contentView addSubview:descrip];  //here add subview to texview not content view