From d4b5f127f5630fccaf4667344d31ae25e83c7302 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Sun, 19 Feb 2012 19:23:34 +0000 Subject: [PATCH] Updated sample code. --- Sample/PegasusSample/PGViewController.m | 21 ++++++++++++++++++++- Sample/PegasusSample/UI/sample1.xml | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Sample/PegasusSample/PGViewController.m b/Sample/PegasusSample/PGViewController.m index abe8daa..e2c8e3a 100644 --- a/Sample/PegasusSample/PGViewController.m +++ b/Sample/PegasusSample/PGViewController.m @@ -32,10 +32,29 @@ - (void)didReceiveMemoryWarning - (void)viewDidLoad { [super viewDidLoad]; + + // Here, we load sample1.xml (from the UI group): NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sample1.xml"]; PGView *pegasusView = [PGView viewWithContentsOfFile:filePath]; + + [self.view addSubview:pegasusView.view]; // pegasusView.view is the actual underlying UIView view + + // We will now show how you can dynamically alter the view at runtime. We will change the image and then + // change the text "dinosaur" to "soldier" in the prompt (comment this out to see the original view). + + // Start by changing the picture + UIImageView *pictureView = (UIImageView *)[pegasusView findViewWithID:@"picture"]; // Find the view tagged with "picture". (Notice how a normal UIImageView is returned.) + UIImage *newImage = [UIImage imageNamed:@"soldier.png"]; + pictureView.image = newImage; + // We also need to resize the image view for the new image: + CGRect frame = pictureView.frame; + frame.size = newImage.size; + pictureView.frame = frame; + + // And now we change the label text: + UILabel *promptLabel = (UILabel *)[pegasusView findViewWithID:@"prompt"]; + promptLabel.text = [promptLabel.text stringByReplacingOccurrencesOfString:@"dinosaur" withString:@"soldier"]; - [self.view addSubview:pegasusView.view]; } - (void)viewDidUnload diff --git a/Sample/PegasusSample/UI/sample1.xml b/Sample/PegasusSample/UI/sample1.xml index 153db4e..849f63b 100644 --- a/Sample/PegasusSample/UI/sample1.xml +++ b/Sample/PegasusSample/UI/sample1.xml @@ -26,11 +26,11 @@ - + -