CGRect height not working

Discussion in 'iOS Programming' started by StevenHu, Mar 25, 2010.

  1. StevenHu macrumors member

    Sep 3, 2009
    Southern CA
    I borrowed this code from TextView in UICatalog (Apple developer site), and added it to a view already containing controls. It filled the whole page. I tried to modify its size with the addition of CGRectMake, but the height continues to be a whole page, extending up off the screen. So the lower left point of the rectangle is x20, y168, width is properly 280, but the height goes up off the top of the Simulator instead of just 90px.

    Why doesn't the height reflect 90px up from the x/y point?


    // Following code comes from Text View in UICatalog
    - (void)setupTextView
    	CGRect frame = CGRectMake(20,168,280,90); // Added
    	self.textView = [[[UITextView alloc] initWithFrame:frame] autorelease];
    //	self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; // Original code
    	self.textView.textColor = [UIColor blackColor];
    	self.textView.font = [UIFont fontWithName:@"Arial" size:16];
    	self.textView.delegate = self;
    	self.textView.backgroundColor = [UIColor whiteColor];
    	self.textView.textColor = [UIColor blueColor]; // Added
    	self.textView.text = @"Notes ";
    	self.textView.returnKeyType = UIReturnKeyDefault;
    	self.textView.keyboardType = UIKeyboardTypeDefault;	// use the default type input method (entire keyboard)
    	self.textView.scrollEnabled = YES; // YES enables scrolling by flicking with finger. 
    	// this will cause automatic vertical resize when the table is resized
    	self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    	// note: for UITextView, if you don't like autocompletion while typing use:
    	// myTextView.autocorrectionType = UITextAutocorrectionTypeNo;
    	[self.view addSubview: self.textView];
  2. StevenHu thread starter macrumors member

    Sep 3, 2009
    Southern CA
    Never mind. I created the text view in IB and now it works fine!


Share This Page