设置UIView的位置和尺寸

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>  



                                                                                                       



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值