UI基础2控件:UILabel,UIImageView

#import "AppDelegate.h"

#import "ViewController.h"

//设置宏定义,就是用内容替换变量名,可随意替换

#define kCount @"我想改的名字"//#define k常量名(k开头后面是:驼峰命名法) @"改动的内容"

#define kLabelX label.frame.origin.x


@interface AppDelegate ()


@end


@implementation AppDelegate

/*

 控件之间的继承关系:UILabel继承自UIView

 UILableUIFont,UIColor都是类,都需要实例化

 UIImageView

 */




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    

    ViewController *vc = [[ViewController alloc]init];

    //    根视图控制器

    self.window.rootViewController = vc;

    //    此处设置父视图背景颜色

    self.window.backgroundColor = [UIColor whiteColor];

    //   ⭐️⭐️⭐️⭐️⭐️⭐️window显示的方法:makeKeyAndVisible让窗口是 主窗口 并且是显示在手机屏幕上,必须自己创建窗口,必须添加根视图控制器

    [self.window makeKeyAndVisible];


    


//    UIView显示一块有颜色的视图

//    UIView *view = [[UIView alloc]init];

//    view.frame = CGRectMake(100, 100, 300, 300);

    

//UILabel:标签控件,适合放一些短的文本

//    1.label对象实例化,任何对象都要实例化

    UILabel *label = [[UILabel alloc]init];

    

//  label设置frame

    label.frame = CGRectMake(200, 200, 200, 300);

    label.backgroundColor = [UIColor redColor];

    [self.window addSubview:label];

    

//    UILabel设置文本,独有属性

    label.text = @"我们都有一个家,名字叫中华";

    

//  给文本设置字体颜色

    label.textColor = [UIColor greenColor];

//    UILabel文本 设置对齐方式,居右,居中

    label.textAlignment = NSTextAlignmentRight;

    label.textAlignment = NSTextAlignmentCenter;

//    系统默认字体,并设置字体大小,36为字号

    label.font = [UIFont systemFontOfSize:36];

    

//    加粗的同时设置字号大小

    label.font = [UIFont boldSystemFontOfSize:36];

    

//    倾斜并设置字体大小

    label.font = [UIFont italicSystemFontOfSize:36];

    

//    设置阴影和阴影颜色

    label.shadowColor = [UIColor blackColor];

//    设置阴影偏移量,设置的是阴影部分点的坐标x:5y:5

    label.shadowOffset = CGSizeMake(5, 5);

    

//    内容过多时,设置正确的行数才能显示完毕,如果显示不完,调节lable的高度;当设置为0时,为自适应行数。

    label.numberOfLines = 1;

    

// 设置一行显示完全部的内容,需要label.numberOfLines = 1 1行;

    label.adjustsFontSizeToFitWidth = YES;

    

// 设置一个图片控件,用来显示图片

    UIImageView *imagView = [[UIImageView alloc]init];//UIImageView继承自UIView,command+ UIImageView  可显示

//    imagView.image图片都需要加后缀,png格式除外

//    imagView.image = [UIImage imageNamed:@"5.tiff"];

    imagView.frame = CGRectMake(10, 10, 400, 300);

    [self.window addSubview:imagView];

//    创建有图片内容的图片对象

    UIImage *image1 = [UIImage imageNamed:@"5.tiff"];

    UIImage *image2 = [UIImage imageNamed:@"12.tiff"];

//    放置图片添加对象

    imagView.animationImages = @[image1,image2];//添加的对象是一个数组

//    设置时间间隔

    imagView.animationDuration = 1;

//    设置重复次数,0为无限次 NSNotFound为无穷大

    imagView.animationRepeatCount = NSNotFound;

//    ⭐️⭐️⭐️⭐️⭐️开始动画⭐️⭐️⭐️⭐️

    [imagView startAnimating];//重要


//  ⭐️⭐️⭐️延时几秒后执行相应的方法 使用selector声明的方法必须实现,否则会崩溃⭐️⭐️⭐️⭐️

    [self performSelector:@selector(start) withObject:nil afterDelay:5];

    

    UILabel *la = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 49)];

    la.backgroundColor = [UIColor redColor];

    la.text = kCount;

    [self.window addSubview:la];

    

//    第一种方法

    NSLog(@"labelx值为%.2f",la.frame.origin.x);

//    第二种方法

//CGRectGetMinX:相当于视图的原点x的坐标

    NSLog(@"%.2f",CGRectGetMidY(la.frame));

    

//    UIScreen可以帮助获取各种屏幕的宽和高

    NSLog(@"屏幕的宽:%f",[UIScreen mainScreen].bounds.size.width);

    NSLog(@"屏幕的高:%f",[UIScreen mainScreen].bounds.size.height);

    

    //在某个方向上让图片自适应,已达到最好看的效果。

    imagView.contentMode = UIViewContentModeScaleAspectFit;

    

    //让图片充满整个frame

    imagView.contentMode = UIViewContentModeScaleToFill;

    //取到图片的相应位置,并放到屏幕上,会超出设置的图片试图Frame

    imagView.contentMode = UIViewContentModeRight;

    

    //裁剪掉超出试图frame的部分

    imagView.clipsToBounds = YES;

    

    [self.window addSubview:imagView];


    return YES;

}


- (void)start{

    NSLog(@"一生有爱何惧风飞沙");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值