Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to go down dynamicaly in UIScrollView?
  2. -(void) log:(NSString *)msg
  3. {
  4.     // alocate and initialize scroll
  5.     UIScrollView *myScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 460.0f)];
  6.     // alocate and initialize label
  7.     UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 320.0f, 460.0f)];
  8.  
  9.     myLabel.text = msg; //a long text
  10.  
  11.     // set line break mode to word wrap
  12.     myLabel.lineBreakMode = UILineBreakModeWordWrap;
  13.     // set number of lines to zero
  14.     myLabel.numberOfLines = 0;
  15.     // resize label
  16.     [myLabel sizeToFit];
  17.  
  18.     // set scroll view size
  19.     myScroll.contentSize = CGSizeMake(myScroll.contentSize.width, myLabel.frame.size.height);
  20.     // add myLabel
  21.     [myScroll addSubview:myLabel];
  22.     // add scroll view to main view
  23.     [self.view addSubview:myScroll];
  24.     // release label and scroll view
  25.  
  26.     [myLabel release];
  27.     [myScroll release];
  28. }
  29.        
  30. [scrollView setContentOffset:CGPointMake(x, y) animated:YES];