Skip to content

Commit

Permalink
Updated sample code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanellis committed Feb 19, 2012
1 parent 950e587 commit d4b5f12
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion Sample/PegasusSample/PGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sample/PegasusSample/UI/sample1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

<scrollview frame="{{100,40}, {100,100}}" contentSize="{278,173}">

<imageview frame="{{0,0}, {278,173}}" image="dinosaur.png" />
<imageview id="picture" frame="{{0,0}, {278,173}}" image="dinosaur.png" />

</scrollview>

<label frame="{{40,160}, {240, 27}}" text="Which part of the dinosaur do you see?" adjustsFontSizeToFitWidth="yes" backgroundColor="clear" textColor="white" />
<label id="prompt" frame="{{40,160}, {240, 27}}" text="Which part of the dinosaur do you see?" adjustsFontSizeToFitWidth="yes" backgroundColor="clear" textColor="white" />

<textfield frame="{{40,200}, {240,27}}" placeholder="Enter text" borderStyle="rounded-rect" />

Expand Down

0 comments on commit d4b5f12

Please sign in to comment.