UIView

import "AppDelegate.h"

// 宏定义颜色

define COLORRGB(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

@interface AppDelegate ()

@end

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
//  创建一个UI view对象
UIView *view = [[UIView alloc]init];
UIView *view1 = [[UIView alloc]init];
//  设置它的frame
view.frame = CGRectMake(0, 100,100 , 100);
view1.frame = CGRectMake(0, 100, 100, 100);
//  设置背景颜色
//  宏定义颜色的使用  view.backgroundColor = COLORRGB(100, 100, 100, 1);
view.backgroundColor = [UIColor blueColor];
view1.backgroundColor = [UIColor redColor];
//  呈现view对象
[self.window addSubview:view];
[self.window addSubview:view1];

// [self.window bringSubviewToFront:<#(nonnull UIView *)#>]

[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

// UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 150)];
// view2.backgroundColor = [UIColor blueColor];
// [self.window addSubview:view2];
// // 得到view2的父view
// id supView = view2.superview;
// NSLog(@"%p\n%p",supView,self.window);
//
// // 判断对象类型
// BOOL result = [supView isKindOfClass:[UIWindow class]];
// NSLog(@"result = %d",result);
//
// // 得到view2的各个参数
// float x = view2.frame.origin.x;
// float y = view2.frame.origin.y;
// float width = view2.frame.size.width;
// float height = view2.frame.size.height;
//
// NSLog(@"view2Frame--%@",NSStringFromCGRect(view2.frame));
//
// NSLog(@"view2Bounds--%@",NSStringFromCGRect(view2.bounds));
//
// NSLog(@"view2FrameByPoint--%@",NSStringFromCGPoint(view2.frame.origin));
//
// NSLog(@"view2FrameBySize--%@",NSStringFromCGSize(view2.frame.size));
//
// NSLog(@"x = %.1f,y = %.1f,width = %.1f,height = %.1f",x,y,width,height);
// // bounds是本身的原点,只会影响它的子view
// view2.bounds = CGRectMake(100, 100, 100, 150);
//
//// [view2 setBounds:CGRectMake(50, 50, 100, 100)];
//
// // 以view2作为父view,新建一个view0
// UIView *view0 =[[UIView alloc]initWithFrame:CGRectMake( 50, 50, 50, 50)];
// view0.backgroundColor = [UIColor yellowColor];
// [view2 addSubview:view0];
// // 打印view2的center
// NSLog(@"view2Center--%@",NSStringFromCGPoint(view2.center));
// // 更改center
// // { center的(x,y)本质上就是父view的frame(x,y),如果改变center,frame(x,y)也会随之改变}
// view2.center = CGPointMake(100, 200);
//
// // 把view2的center设置成window的center
// view2.center = CGPointMake(self.window.frame.size.width/2, self.window.frame.size.height/2);
//
// // 把view2隐藏
// // view2.hidden = YES;
//
// // 设置透明度,取值范围(0,1) 0:表示透明 ; 1:表示不透明
// view2.alpha = 1;
//
// // 得到它的所有子view (如果需要得到子视图中的某一类视图,需要遍历的时候配合iskindofclass来使用)
// // view2.subviews
//
// // 给view设置标记(tag) 建议从1000以后设置
// view2.tag = 100;
//
// // 从父视图上通过tag值得到相应的子视图
// UIView *tagView = [self.window viewWithTag:100];

//  创建 UILable (标签)
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(100, 100,  100, 100)];
//  lable呈现文字
lable.text = @"我是四班最帅的!我是四班最帅的!我是四班最帅的!我是四班最帅的!";
//  设置字体颜色
lable.textColor = [UIColor whiteColor];
//  设置字体大小
[lable setFont:[UIFont systemFontOfSize:10]];
//  显示不完全时,省略号的位置
lable.lineBreakMode = NSLineBreakByTruncatingMiddle;
//  设置文字显示位置 (枚举类型:0居左,1居中,2居右)
lable.textAlignment = NSTextAlignmentCenter;
//  设置行数(默认的为1行,0表示自动换行)
[lable setNumberOfLines:1];
//  设置字体阴影颜色
lable.shadowColor = [UIColor yellowColor];
//  设置阴影偏移量
lable.shadowOffset = CGSizeMake(3, 3);

//  设置lable的背景颜色
lable.backgroundColor = [UIColor blueColor];
[self.window addSubview:lable];

[self.window setRootViewController:[[UIViewController alloc]init]];
return YES;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 初识iOS APP开发#### 在iOS APP开发中, main函数仍是程序的入口和出口, 但main函数不需要...
    DeanYan阅读 6,340评论 0 3
  • UIView(控件) 功能一:界面显示1. 屏幕上显示的所有UI元素都叫做控件,也有人叫做视图、组件;按钮(UIB...
    翻这个墙阅读 661评论 0 0
  • 一、初始化方法 1、- initWithFrame: UIView *view = [[UIView alloc]...
    默默_David阅读 2,571评论 1 3
  • 1、概念 UIView表示 屏幕上的一块矩形区域,它在app占有绝对重要的地位,因为ios中几乎所有可视化控件都是...
    lilinjianshu阅读 604评论 0 0
  • 1、背景颜色、透明度以及是否隐藏 @property(nullable,nonatomic,copy)UIColo...
    赵亦晨阅读 349评论 0 0