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. }
} |