//
Viewcontroller.m
01-playplane
//
Created by Wang on 16/4/9.
COPYRIGHT©2016 King of the year. All rights reserved.
//
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
[Self setupui];
Additional setup after loading the view, typically from a nib.
}
Setup interface
-(void) setupui{
Set background
Uiimageview *backgroundpicture = [[Uiimageview alloc]init];
Set the background in place.
Backgroundpicture.image = [UIImage imagenamed:@ "background"];
Adjust background size
Backgroundpicture.frame = Self.view.frame;
Add to and view
[Self.view Addsubview:backgroundpicture];
Add aircraft
UIButton *plane = [[UIButton alloc]init];
Two pictures in the default and highlight states
UIImage *normal = [UIImage imagenamed:@ "Hero1"];
UIImage *highlight = [UIImage imagenamed:@ "Hero2"];
[Plane Setimage:normal Forstate:uicontrolstatenormal];
[Plane setimage:highlight forstate:uicontrolstatehighlighted];
Airplane button Size
[Plane SizeToFit];
Airplane button Position
Plane.center=self.view.center;
Add to and view
[Self.view Addsubview:plane];
Add Direction button
CGFloat offset = 100;
[Self adddirbuttonwithimagename:@ "top" offsetpoint:cgpointmake (0,-offset)];
[Self adddirbuttonwithimagename:@ ' left ' Offsetpoint:cgpointmake (-offset,0)];
[Self adddirbuttonwithimagename:@ ' right ' offsetpoint:cgpointmake (offset, 0)];
[Self adddirbuttonwithimagename:@ "bottom" offsetpoint:cgpointmake (0, offset)];
}
-(void) Adddirbuttonwithimagename: (NSString *) imageName offsetpoint: (cgpoint) offsetpoint{
Determine the location of the four-button center point
Cgpoint Center = cgpointmake (self.view.center.x, self.view.center.y+200);
The size of the button
CGFloat mysize = 40;
Determine the button's frame
CGRect rect = CGRectMake (center.x-mysize*0.5, center.y-mysize*0.5, Mysize, mysize);
UIButton *dirbutton = [[UIButton alloc]init];
//
NSString *nname = [ImageName stringbyappendingstring:@ "_normal"];
NSString *hname = [ImageName stringbyappendingstring:@ "_highlighted"];
//
UIImage *normal = [UIImage imagenamed:nname];
UIImage *highlighted = [UIImage imagenamed:hname];
//
[Dirbutton Setimage:normal Forstate:uicontrolstatenormal];
[Dirbutton setimage:highlighted forstate:uicontrolstatehighlighted];
Position
Dirbutton.frame = Cgrectoffset (rect, offsetpoint.x, OFFSETPOINT.Y);
[Self.view Addsubview:dirbutton];
}
@end
Pure code implementation of small aircraft game interface framework