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];
//  創(chuàng)建一個UI view對象
UIView *view = [[UIView alloc]init];
UIView *view1 = [[UIView alloc]init];
//  設(shè)置它的frame
view.frame = CGRectMake(0, 100,100 , 100);
view1.frame = CGRectMake(0, 100, 100, 100);
//  設(shè)置背景顏色
//  宏定義顏色的使用  view.backgroundColor = COLORRGB(100, 100, 100, 1);
view.backgroundColor = [UIColor blueColor];
view1.backgroundColor = [UIColor redColor];
//  呈現(xiàn)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的各個參數(shù)
// 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)本質(zhì)上就是父view的frame(x,y),如果改變center,frame(x,y)也會隨之改變}
// view2.center = CGPointMake(100, 200);
//
// // 把view2的center設(shè)置成window的center
// view2.center = CGPointMake(self.window.frame.size.width/2, self.window.frame.size.height/2);
//
// // 把view2隱藏
// // view2.hidden = YES;
//
// // 設(shè)置透明度,取值范圍(0,1) 0:表示透明 ; 1:表示不透明
// view2.alpha = 1;
//
// // 得到它的所有子view (如果需要得到子視圖中的某一類視圖,需要遍歷的時候配合iskindofclass來使用)
// // view2.subviews
//
// // 給view設(shè)置標(biāo)記(tag) 建議從1000以后設(shè)置
// view2.tag = 100;
//
// // 從父視圖上通過tag值得到相應(yīng)的子視圖
// UIView *tagView = [self.window viewWithTag:100];

//  創(chuàng)建 UILable (標(biāo)簽)
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(100, 100,  100, 100)];
//  lable呈現(xiàn)文字
lable.text = @"我是四班最帥的!我是四班最帥的!我是四班最帥的!我是四班最帥的!";
//  設(shè)置字體顏色
lable.textColor = [UIColor whiteColor];
//  設(shè)置字體大小
[lable setFont:[UIFont systemFontOfSize:10]];
//  顯示不完全時,省略號的位置
lable.lineBreakMode = NSLineBreakByTruncatingMiddle;
//  設(shè)置文字顯示位置 (枚舉類型:0居左,1居中,2居右)
lable.textAlignment = NSTextAlignmentCenter;
//  設(shè)置行數(shù)(默認(rèn)的為1行,0表示自動換行)
[lable setNumberOfLines:1];
//  設(shè)置字體陰影顏色
lable.shadowColor = [UIColor yellowColor];
//  設(shè)置陰影偏移量
lable.shadowOffset = CGSizeMake(3, 3);

//  設(shè)置lable的背景顏色
lable.backgroundColor = [UIColor blueColor];
[self.window addSubview:lable];

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

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 初識iOS APP開發(fā)#### 在iOS APP開發(fā)中, main函數(shù)仍是程序的入口和出口, 但main函數(shù)不需要...
    DeanYan閱讀 6,322評論 0 3
  • UIView(控件) 功能一:界面顯示1. 屏幕上顯示的所有UI元素都叫做控件,也有人叫做視圖、組件;按鈕(UIB...
    翻這個墻閱讀 656評論 0 0
  • 一、初始化方法 1、- initWithFrame: UIView *view = [[UIView alloc]...
    默默_David閱讀 2,570評論 1 3
  • 1、概念 UIView表示 屏幕上的一塊矩形區(qū)域,它在app占有絕對重要的地位,因為ios中幾乎所有可視化控件都是...
    lilinjianshu閱讀 604評論 0 0
  • 1、背景顏色、透明度以及是否隱藏 @property(nullable,nonatomic,copy)UIColo...
    趙亦晨閱讀 348評論 0 0