Create a Simple iOS On-Screen Logging Console
Tuesday, March 13, 2012, by Sebastian Dwornik

Sometimes it can be useful to have a simple text console on-screen within your iOS app to output status info and other messages that can help analyze a running app.

Hence the creation of textViewLog:() function.

Simply add the following UItextView control setup.

@property (nonatomic, strong) IBOutlet UITextView *textConsole;
@synthesize textConsole;

Insert a UItextView control within your View and connect its outlet to our property.

UItextview connections


Finally drop in the code below.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// It's almost like NSLog, but directed to a UITextView control.
//
// usage example:  [self textViewLog:@"%@", myVar];
//
- (void)textViewLog:(NSString *)firstArg, ...
{
    va_list args;

    va_start(args, firstArg);

    NSString *log_msg = [[NSString alloc] initWithFormat:firstArg arguments:args];

    self.textConsole.text = [NSString stringWithFormat:@"%@%@\n", self.textConsole.text, log_msg];

    // Support auto-scroll.
    NSRange range = NSMakeRange(self.textConsole.text.length - 1, 1);
    [self.textConsole scrollRangeToVisible:range];

}


And voila!  You have yourself a quick and simple on-screen logging console.

iPhone 4 with console

You can download the above sample project too.


Re: Create a Simple iOS On-Screen Logging Console

No posts

This topic is archived. No further replies will be accepted.

B_other_topics

 
Groups

 

 
 
Copyright © 2007 - 2013 Applied PDA Software, Inc. Fresh Lime Studio
All products mentioned on this web site are owned and copyrighted by their respective companies.