I had a text view and i was taking chat that came in from the internet and was printing it but i wanted more colors than a textview had to format the chat.
I replaced the textview with a scrollview and in viewdidload i attempted ( seemed to work) to attach my view class to it.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_myconsoleview = [[ConsoleView alloc] initWithFrame:[self._scview bounds]];
[_myconsoleview setBackgroundColor: [UIColor yellowColor]];
[self._scview addSubview:_myconsoleview];
[self._scview setNeedsDisplay];
}
well as text got to the bottom it didn't scroll ( i tried dragging the text are with the mouse and looked for scroll bars).
so this example core text program says oh thats easy to get scrolling. just make my custom view (ConsoleView) inherit the scroll view itself. So i try this and add this now:
@interface ConsoleView :UIScrollView<UIScrollViewDelegate>
still no scrolling. no scroll bars. no indication and i'm using the ipad simulator so far, of any kind of scrolling. In ConsoleView i want to do something very polished eventually but for now i'm just printing a single string. But the string gets longer as i get more text as i'm appending to it.
i tried this in my sendtext method. this hits when they hit a button to send the text they type in this textfield to the server:
[myconsoleviewid addNewText:newText];
[_scview scrollRectToVisible:[_scview bounds] animated: TRUE];
[_scview setNeedsDisplay];
I honestly am not sure i can claim the above would work but i figured something might work. any ideas? I'm fairly new to ios programming having started about 2 months ago and worked on it off and on so far. In java or android there doesn't seem to be much more to getting like a console to scroll than to add it to some scroll control. But IOS is proving trickier.
Mike
edit. this is my draw rectangle which is suppose to print the string which gets longer and longer. its in consoleview:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0); CGMutablePathRef path = CGPathCreateMutable(); //1
CGPathAddRect(path, NULL, self.bounds );
CTFramesetterRef framesetter =
CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attString); //3
CTFrameRef frame =
CTFramesetterCreateFrame(framesetter,
CFRangeMake(0, [attString length]), path, NULL);
CTFrameDraw(frame, context); //4
CFRelease(frame); //5
CFRelease(path);
CFRelease(framesetter);
}