swift编写iphone软件,自适应屏幕,纯代码实现


//
//  ViewController.swift
//  kids
//
//  Created by yuexiaosheng 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 any 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//屏幕高度
 
        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("注册", 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("登陆", forState: UIControlState.Normal)
        registerBtn2.addTarget(self, action: "goList:", forControlEvents:UIControlEvents.TouchUpInside)
        self.view.addSubview(registerBtn2)
 
        var webView = UIWebView()
        var url = NSURL(string:"http://www.baidu.com")
        var urlRequest = NSURLRequest(URL:url!)
        webView.frame = CGRectMake(0, 20, 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 resources that can be recreated.
    }
 
 
}
如果你是一名技术人员可加我QQ 2651-0442-02,如果你是java技术人还可以加入QQ群 1784-9136-0
你将得到的不仅仅是技术的交流,还有职业机会,人生解惑.
首发地址:月小升博客https://java-er.com/blog/xcode-swift-code-screen-auto/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
此条目发表在 MAC, Xcode 分类目录,贴了 , , , , 标签。将固定链接加入收藏夹。
既然来了,就评论一下,不会怀孕的

swift编写iphone软件,自适应屏幕,纯代码实现》有 1 条评论

  1. 好文章 说:

    支持一下、感谢分享

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">