iOS development Swift uses code from the adaptive interface

Source: Internet
Author: User

The month small liter once used the interface to carry on the adaptation, as does not have the systematic Xcode training person, is too troublesome. Or the code comes directly.

You can set the size of a component by directly calculating the width of the screen.

The code is as follows Copy Code

//
Viewcontroller.swift
Kids
//
Created by on 15/9/4.
Copyright (c) 2015 Acrowdkids. All rights reserved.
//

Import Uikit

Class Viewcontroller:uiviewcontroller {

@IBOutlet weak var wb:uiwebview!
@IBOutlet weak var bn_blue:uibutton!

@IBOutlet weak var bn_org:uibutton!

@IBOutlet weak var lb_msg:uilabel!
var webview:uiwebview?
Override Func Viewdidload () {
Super.viewdidload ()

Do no additional setup after loading the view, typically from a nib.
Lb_msg.text = Self.view.bounds.width.description
var width = self.view.bounds.width.description
var height = self.view.bounds.height.description
var fwidth = (width as nsstring). Floatvalue
var fheight = (height as nsstring). floatvalue//screen Height

Let sizew:cgfloat = CGFloat (FWIDTH/2)
Let posy:cgfloat = CGFloat (fheight-40)

Let sizewebview:cgfloat = CGFloat (fwidth)
Let posywebview:cgfloat = CGFloat (fheight-60)


Let Registerbtn:uibutton = UIButton ()
Registerbtn.frame = CGRectMake (0, Posy, Sizew, 40)
Registerbtn.backgroundcolor = Uicolor.orangecolor ()
Registerbtn.settitle ("registered", ForState:UIControlState.Normal)
Registerbtn.addtarget (Self, Action: "Golist:", ForControlEvents:UIControlEvents.TouchUpInside)
Self.view.addSubview (REGISTERBTN)

Let Registerbtn2:uibutton = UIButton ()
Registerbtn2.frame = CGRectMake (Sizew, Posy, Sizew, 40)
Registerbtn2.backgroundcolor = Uicolor.bluecolor ()
Registerbtn2.settitle ("Landing", ForState:UIControlState.Normal)
Registerbtn2.addtarget (Self, Action: "Golist:", ForControlEvents:UIControlEvents.TouchUpInside)
Self.view.addSubview (REGISTERBTN2)

var webview = UIWebView ()
var url = nsurl (string:http://www.111cn.net)
var urlrequest = nsurlrequest (url:url!)
Webview.frame = CGRectMake (0, Sizewebview, Posywebview)
Webview.loadrequest (URLRequest)
Self.view.addSubview (WebView)


}

@IBAction func golist (sender:anyobject) {
var Rootvc:listviewcontroller = Listviewcontroller (nibname: "Listviewcontroller", Bundle:nil)

Let Nvc:uinavigationcontroller = Uinavigationcontroller (ROOTVIEWCONTROLLER:ROOTVC)
Nvc.setnavigationbarhidden (True, animated:true)

Self.presentviewcontroller (NVC, Animated:true, Completion:nil)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any of the can is recreated.
}


}

Related Article

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.