First on the interface builder put 6 Rectbutton, vertical, a row of three
And we'll look at the code below.
. h File Code
1//
2//AutoSizeViewController.h
3//AutoSize
4//
5//Created by Scott on 10-10-26.
6//Copyright __mycompanyname__. All rights reserved.
7//
8
9 #import
10
One @interface Autosizeviewcontroller:uiviewcontroller {
UIButton *button1;
UIButton *button2;
UIButton *button3;
UIButton *button4;
UIButton *button5;
UIButton *button6;
18}
19
@property (nonatomic,retain) iboutlet UIButton *button1;
@property (nonatomic,retain) iboutlet UIButton *button2;
@property (nonatomic,retain) iboutlet UIButton *button3;
@property (nonatomic,retain) iboutlet UIButton *button4;
@property (nonatomic,retain) iboutlet UIButton *button5;
@property (nonatomic,retain) iboutlet UIButton *button6;
Num @end
27
Here we look at the code for. M
//
Autosizeviewcontroller.m
AutoSize
//
Created by Scott on 10-10-26.
Copyright __mycompanyname__. All rights reserved.
//
#import "AutoSizeViewController.h"
@implementation Autosizeviewcontroller
@synthesize button1;
@synthesize button2;
@synthesize Button3;
@synthesize Button4;
@synthesize button5;
@synthesize Button6;
/*
The designated initializer. Override to perform setup this is required before the view is loaded.
-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil {
if (self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil])
{
Custom initialization
}
return self;
}
*/
/*
Implement Loadview to create a view hierarchy programmatically, without using a nib.
-(void) Loadview {
}
*/
/*
Implement Viewdidload to did additional setup after loading the view, typically from a nib.
-(void) Viewdidload {
[Super Viewdidload];
}
*/
Override to allow orientations than the default portrait orientation.
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation {
Return YES to supported orientations
Return (interfaceorientation!= uiinterfaceorientationportraitupsidedown);
}
-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation Duration: (nstimeinterval) Duration
{
if (interfaceorientation==uiinterfaceorientationportrait | | interfaceorientation== Uiinterfaceorientationportraitupsidedown) {
Button1.frame=cgrectmake (20, 20, 125, 125);
Button2.frame=cgrectmake (175, 20, 125, 125);
Button3.frame=cgrectmake (20, 168, 125, 125);
Button4.frame=cgrectmake (175, 168, 125, 125);
Button5.frame=cgrectmake (20, 315, 125, 125);
Button6.frame=cgrectmake (175, 315, 125, 125);
}else {
Button1.frame=cgrectmake (20, 20, 125, 125);
Button2.frame=cgrectmake (20, 155, 125, 125);
Button3.frame=cgrectmake (177, 20, 125, 125);
Button4.frame=cgrectmake (177, 155, 125, 125);
Button5.frame=cgrectmake (328, 20, 125, 125);
Button6.frame=cgrectmake (328, 155, 125, 125);
}
}
-(void) didreceivememorywarning {
Releases the view if it doesn ' t have a superview.
[Super didreceivememorywarning];
Release any cached of data, images, etc that aren ' t in use.
}
-(void) Viewdidunload {
Release any retained subviews of the main view.
e.g. Self.myoutlet = nil;
Self.button1=nil;
Self.button2=nil;
Self.button3=nil;
Self.button4=nil;
Self.button5=nil;
Self.button6=nil;
[Super Viewdidunload];
}
-(void) Dealloc {
[Button1 release];
Button2.release;
Button3.release;
Button4.release;
Button5.release;
Button6.release;
[Super Dealloc];
}
@end