Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
Hi I am trying to place a UITextField inside a custom scrollable view. The only problem is, if the text in the textfield becomes to long, it disappears when a user scrolls. Below is my code

Code:
 // ScrollView
    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.height -= 44;
    
    // Text View
    _textView = [[UITextView alloc] init];
    _textView.editable = NO;
    _textView.scrollEnabled = YES;
    _textView.font = [UIFont appFontOfSize:14.0f];
    _textView.textColor = [UIColor eventInfoColor];
    _textView.backgroundColor = [UIColor whiteColor];
    _textView.text = _notes;
    [_textView setFrame:CGRectMake(5, 0, 290, 0)]; 
    
    // Size the content
    [self.view addSubview:_textView];
    [_textView removeFromSuperview];
    _textView.height = _textView.contentSize.height;
    
    // Rounded View
    UIView* roundedView = [UIView roundedView];
    roundedView.frame = CGRectMake(10, 10, self.view.width - 20, _textView.height);
    roundedView.opaque = NO;
    roundedView.layer.shouldRasterize = YES;
    roundedView.layer.rasterizationScale = [UIScreen mainScreen].scale;
    [roundedView addSubview:_textView];
    
    // Container
    [scrollView addSubview:roundedView];
    scrollView.contentSize = CGSizeMake(self.view.width, roundedView.height + 20);
    
    // Done
    [self.view addSubview:scrollView];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.