Pure code implementation of small aircraft game interface framework

Source: Internet
Author: User

//

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.