//创建并设置路径,     //通过

作者: 编程  发布:2019-11-21

 

//应用程序代理类

 

 

//AppDelegate中的方法都是UIApplicationDelegatez的商业事务形式

 

     let mview = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height:     UIScreen.main.bounds.height))

//应用程序类

亟需世襲UIView 重写draw 方法

 

class AppDelegate: UIResponder, UIApplicationDelegate {

 

     //获取delegate

//应用程序窗口,是 AppDelete类的习性

 9159.com 1

        let delegate  = UIApplication.shared.delegate as! AppDelegate

var window: UIWindow?

 

        

//应用程序加载成功触发那些办法

 

        mview.backgroundColor = UIColor(white: 0.5, alpha: 0.8)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

import UIKit

     //添加tag

// Override point for customization after application launch.

class ViewController: UIViewController {

        mview.tag = 1

//想再window对象增多对象,就在此个方法中贯彻

 

     //增加视图

//屏幕类UIScreen

    override func viewDidLoad() {

        delegate.window?.addSubview(mview)

//UIScreen.main拿到显示屏对象

        super.viewDidLoad()

     //通过tag 从window移除视图

//UIScree.main.bounds

        let mview = myView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))

        delegate.window?.viewWithTag(1)?.removeFromSuperview()

self.window=UIWindow(frame: UIScreen.main.bounds)

        self.view.addSubview(mview)

self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green: 0.8069495559, blue: 0.5823518634, alpha: 1)

        

//让Window成为应用程序的主窗口,并使其可以知道

        let mview2 = myView(frame: CGRect(x: 0, y:200, width: 300, height: 300))

self.window?.makeKeyAndVisible()

        self.view.addSubview(mview2)

//给window设置跟精算调节器(今后创设了解)

    }

self.window?.rootViewController=UIViewController()

 

//日常应用程序唯有二个window对象

    override func didReceiveMemoryWarning() {

return true

        super.didReceiveMemoryWarning()

}

        // Dispose of any resources that can be recreated.

9159.com ,//应用程序就要撤消活跃状态是触发

    }

func applicationWillResignActive(_ application: UIApplication) {

    

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

}

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

 

}

 

//已经进来后台是触发

 

func applicationDidEnterBackground(_ application: UIApplication) {

 

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

//自定义View

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

 

}

class  myView: UIView {

//将在步入前台时接触

    

func applicationWillEnterForeground(_ application: UIApplication) {

    override init(frame: CGRect) {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

        super.init(frame: frame)

}

     //清除背景颜色

//应用程序已经变得生意盎然时接触

        self.backgroundColor = UIColor.clear

func applicationDidBecomeActive(_ application: UIApplication) {

    }

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    

}

    required init?(coder aDecoder: NSCoder) {

//就要停止触发

        super.init(coder: aDecoder)

func applicationWillTerminate(_ application: UIApplication) {

    }

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

    override func draw(_ rect: CGRect) {

}

        super.draw(rect)

}

        

何敏  14:54:55

        //获取绘图上下文

class AppDelegate: UIResponder, UIApplicationDelegate {

        guard let context = UIGraphicsGetCurrentContext() else { return  }

//应用程序窗口,是 AppDelete类的个性

        

var window: UIWindow?

        

//应用程序加载成功触发那个主意

        //创立并安装路线

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        let path = CGMutablePath()

// Override point for customization after application launch.

        path.move(to: CGPoint(x: 10, y: 10))

//想再window对象增添对象,就在这里个艺术中落到实处

        path.addLine(to: CGPoint(x: 200, y: 222))

//屏幕类UIScreen

        let secondP = CGMutablePath()

//UIScreen.main得到显示屏对象

        secondP.move(to: CGPoint(x: 300, y: 0 ))

//UIScree.main.bounds

        secondP.addLine(to: CGPoint(x: 200, y: 222))

self.window=UIWindow(frame: UIScreen.main.bounds)

        //设置描线颜色

self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green: 0.8069495559, blue: 0.5823518634, alpha: 1)

        context.setStrokeColor(UIColor.black.cgColor)

//让Window成为应用程序的主窗口,并使其可以预知

        //将路线加多到上下文

self.window?.makeKeyAndVisible()

        context.addPath(path)

//给window设置跟精算调整器(以后制作驾驭)

        context.addPath(secondP)

self.window?.rootViewController=UIViewController()

        //设置线宽

//平时应用程序唯有八个window对象

        context.setLineWidth(10)

//UiView 创立方式

        //最初绘制路线

/*

        context.strokePath()

let redView=UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

    }

redView.backgroundColor=#colorLiteral(red: 1, green: 0.3980397582, blue: 0.7863847613, alpha: 1)

}

//向window增多贰个子视图

 

self.window?.addSubview(redView)

 

//获取显示器的宽

 

let screenWidth = UIScreen.main.bounds.size.width

//获取显示屏的高

let screenHeight=UIScreen.main.bounds.size.height

let greenView = UIView(frame: CGRect(x: screenWidth-100, y: 0, width: 100, height: 100))

greenView.backgroundColor=UIColor.green

self.window?.addSubview(greenView)

let blueView=UIView(frame: CGRect(x: 0, y: screenHeight-100, width: 100, height: 100))

blueView.backgroundColor=#colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)

self.window?.addSubview(blueView)

let yellowView = UIView(frame: CGRect(x: screenWidth-100, y: screenHeight-100, width: 100, height: 100))

yellowView.backgroundColor=UIColor.yellow

self.window?.addSubview(yellowView)

let purpleView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

//purpleView主题点和window大旨点重合

purpleView.center=(self.window?.center)!

purpleView.backgroundColor=#colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)

self.window?.addSubview(purpleView)*/

let centerView=UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

centerView.backgroundColor=UIColor.red

self.window?.addSubview(centerView)

//UIView常用属性

//alpha 透明度 0.0~1.0

centerView.alpha=1.0

//hidden显示隐形 true  掩瞒 false 显示

centerView.isHidden=false

//superView获取到父视图的习性

let fatherView=centerView.superview

fatherView?.backgroundColor=UIColor.yellow

//像centerView增多子视图

let greenView=UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))

greenView.backgroundColor=UIColor.green

//子视图超过父视图边界,就把超过部分剪掉

//centerView.clipsToBounds=true

//tag值属性,给视图增添贰个唯生机勃勃标志

greenView.tag=200

self.window?.addSubview(greenView)

//subView属性,获取子视图属性

let arr=centerView.subviews

let newView=arr[0]

newView.backgroundColor=UIColor.blue

//遵照tag值获取视图对象

let newView2=centerView.viewWithTag(200)

newView2?.backgroundColor=UIColor.gray

return true

}

本文由9159.com发布于编程,转载请注明出处:        //创建并设置路径,     //通过

关键词:

上一篇:没有了
下一篇:没有了