iPhone Objective-C Adding UITextView upon viewDidLoad

November 10, 2009 § 2 Comments

This is a simple approach to draw a UITextView, insert content from a text file within Xcode project, disable editing, and customize font style during loading app.

– (void)viewDidLoad {

[super viewDidLoad];
CGRect viewRect = CGRectMake(0.0, 0.0, 320.0, 420.0);
myTextView = [[UITextView alloc] initWithFrame:viewRect];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = [documentsDirectory stringByAppendingPathComponent:@”sample.txt”];
NSString *filenameString = [NSString stringWithContentsOfFile:filename];
myTextView.text = filenameString;
myTextView.editable = NO;
myTextView.textAlignment = UITextAlignmentCenter;
UIFont *myFont = [UIFont fontWithName:@”Helvetica” size:10.0];
// add Font color
myTextView.font = myFont;
[self.view addSubview:myTextView];
}

Advertisements

§ 2 Responses to iPhone Objective-C Adding UITextView upon viewDidLoad

  • Chewie says:

    Hi there, sorry my english, I suck, but I admit… rs

    I’ve tried use your code, but it didn’t worked.
    The error that I get is that the myTextView is undeclared, just in the line that you create it.

    I’m using SDK4, for iPhone and iPad.

    could you help me ?

    tks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading iPhone Objective-C Adding UITextView upon viewDidLoad at Web Builders.

meta

%d bloggers like this: