UILabel、UIButton

UILabel、UIButton

一、UIViewController:视图控制器,用来管理视图    

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

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

self.window.rootViewController = viewController;  

[self.window makeKeyAndVisible];


二、UILabel:文本控件用来显示文本内容

1、 初始化:   

CGFloat sWidth = CGRectGetWidth([UIScreen mainScreen].bounds); //sWidth 为屏幕的宽

label = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, sWidth - 10 * 2, 200)];


2、添加文字:

label.text = @"我是一只小小小小鸟";

    

3、改变字体大小:

label.font = [UIFont systemFontOfSize:40];

注:

这里将字体的大小改为40

    

4、根据label宽度自动适应字体的宽度,来达到显示全部内容的效果

label.adjustsFontSizeToFitWidth = YES;

注:

如果等于NO则不会自动适应字体的宽度

    

5、更改字体颜色:

label.textColor = [UIColor whiteColor];

注:

whiteColor表示的是将字体的颜色改为白色


6、添加红色阴影:

label.shadowColor = [UIColor redColor];


7、改变阴影方向:

label.shadowOffset = CGSizeMake(3, 5);

注:

1)第一个参数负责左右(宽)(负数:左 正数:右)

2)第二个参数负责上下(高)(负数:上 正数:下)




8、设置文本向左、向右、居中的方法:

label.textAlignment = NSTextAlignmentCenter;

注:

NSTextAlignmentCenter表示设置为居中


9、自动换行:

label.numberOfLines = 100;

    

10、文本框颜色:  

label.backgroundColor = [UIColor clearColor];

注:iOS7.1之前,默认是有边框颜色的(白色)现在默认是透明的

    

11、添加到View上:    

[self.view addSubview:label];

    

三、UIButton:按钮控件点击按钮会触发某个事件

1、初始化:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(120, 400, 120, 120);

[button addTarget:self action:@selector(changeTitle:) forControlEvents:UIControlEventTouchUpInside];

注:

changeTitle: 为触发的方法名


2、添加字体:

[button setTitle:@"点击" forState:UIControlStateNormal];


3、设置点击时的状态:

[button setTitle:@"确定" forState:UIControlStateHighlighted];


4、点击时设置为高亮状态:

button.showsTouchWhenHighlighted = YES;

    

5、设置字体颜色:

1)普通状态下的字体颜色

[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

2)点击为高亮状态时的字体颜色

[button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];

    

5、添加背景图:

1、普通状态时的背景图    

[button setBackgroundImage:[UIImage imageNamed:@"27.png"] forState:UIControlStateNormal];

2)点击为高亮状态时的背景图

[button setBackgroundImage:[UIImage imageNamed:@“12.png"] forState:UIControlStateHighlighted];


6、按钮是否被选中(默认是NO):

button.selected = NO;

    

7、设置背景颜色:

button.backgroundColor = [UIColor grayColor];


8、添加到View:    

[self.view addSubview:button];

    

    

四、图片视图

UIImageView:用来展示图片

UIImageView *imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];

imageView.image = [UIImage imageNamed:@"4127.png"];

[self.view addSubview:imageView];

   

五、View方法:

1、即将显现的时候调用(视图即将被渲染到屏幕的时候)

- (void)viewWillAppear:(BOOL)animated {

//    可以在viewWillAppear 加载数据

}


2、已经显现的时候调用(视图已经被渲染到屏幕的时候)

- (void)viewDidAppear:(BOOL)animated {

    

}


3、视图即将消失在屏幕上的时候调用

- (void)viewWillDisappear:(BOOL)animated {

    

}


4、视图已经消失在屏幕上的时候调用

- (void)viewDidDisappear:(BOOL)animated {

    

}


5、内存不足的时候调用

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值