xcode AppDelegate.m
创建UIWindow简单运用eg:
Objective-C:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *pushVC=[[UIViewController alloc]init];
self.window.rootViewController=pushVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
Swift:
使用?和!来表示可选类型。?表示使用的时候可能为空;!表示使用的时候自动适应
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
self.window?.rootViewController=ViewController()
UIViewController.m创建UIView eg:
Objective-C:
CGRect viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
myView.backgroundColor=[UIColor redColor];
[self.view addSubview:myView];
Swift:
let myView =UIView()
myView.backgroundColor=UIColor.redColor()
myView.frame=CGRectMake(10,10,100,100)
self.view.addSubview(myView)
UIView裁剪效果
设置圆环
self.myView.layer.cornerRadius = 11; //设置圆形的程度
self.myView.layer.masksToBounds = YES; //设置是否切圆
self.myView.layer.borderColor = [[UIColor greenColor]CGColor]; //设置圆周围的颜色
self.myView.layer.borderWidth = 2; //设置圆环的粗细宽度
效果: