My Silver Challenge


I found this challenge really easy - like - bronze easy. :smiley:

First I created some instances to access the objects in my XIB file and connected them up accordingly.

So here we go:


#import <UIKit/UIKit.h>

@interface HeavyViewController : UIViewController

@property (nonatomic, weak) IBOutlet UIView *viewBackground;
@property (nonatomic, strong) IBOutlet UISlider *slider;
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) IBOutlet UIButton *button1;
@property (nonatomic, strong) IBOutlet UIButton *button2; 


I found property methods just easier to work with - we could have just declared our instance variables the normal way, with in the " { } } braces.

Then in my
it was simple to add the needed code:

- (void)viewWillAppear:(BOOL)animated

    [[self slider]setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
    [[self imageView]setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];
    [[self button1]setContentMode:  UIViewContentModeBottomLeft];
    [[self button2]setContentMode:  UIViewContentModeBottomRight]; 

Iā€™m sure there are other ways to do this - as there is with any programming problem.



Had I used this code in my header file:

 _weak IBOutlet UIView *imageView

//More instance variables...

I could have accessed the instances in my implementation file like so:

[imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 

I guess it would be neater and I think I may do it that way in future when accessing instance variables from the header file.