1.说明
iOS里看到的和摸到的都是UIView
视图和窗口展示了应用的的界面,同时负责界面的交互
2.实例
起:使用方法intWithFrame安装frame建立新的View,并将新的View通过addSubview加入到父View中
终:在屏幕中间和屏幕右上角设置两个区域
.h
#import <UIKit/UIKit.h>
@interface UIKitPrjFrame : UIViewController
@end
.m
#import "UIKitPrjFrame.h"
@interface UIKitPrjFrame ()
@end
@implementation UIKitPrjFrame
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectZero];
label1.text = @"右上方";
label1.backgroundColor = [UIColor whiteColor];
label1.frame = CGRectMake(220, 20, 100, 50);
UILabel *label2 = [[UILabel alloc] initWithFrame:label1.frame];
label2.textAlignment = NSTextAlignmentCenter;
label2.backgroundColor = [UIColor whiteColor];
label2.text = @"中心位置";
CGPoint newPoint = self.view.center;
label2.center = newPoint;
[self.view addSubview:label1];
[self.view addSubview:label2];
}
Main.storyboard
<viewController id="vXZ-lx-hvc" customClass="UIKitPrjFrame" customModuleProvider="" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>s
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>