UI——label--button

 

-----------  了解iphone--------

     iphone 4/4s

     尺寸:3.5英寸

     分辨率:640*960

     实际的点(大小):320*480

     

     iphone 5/5s

     尺寸:4.0英寸

     分辨率:640*1136

     实际的点:320*568

     

     iphone6

     尺寸:4.7

     分辨率:750*1334

     实际屏幕的点:(375*667)

     

     iphone Plus

     尺寸:5.5

     分辨率:1080*1920

     实际:(540*960):

     

     怎么设置标签的位置

     (需要设置的标签左上角的坐标以及大小(长,宽)

     注意:控件的形状都是矩形的。

     

     为什么要设置左上角的坐标

     因为屏幕的坐标原点是屏幕的左上角

     

     怎么实际的设置?

     通过oc的结构体CGRect(位置) CGSize(大小) CGPoint(坐标)

------------UILabel-----------

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

  设置显示内容

    label.text = @"学习"; 

    设置标签背景

    label.backgroundColor = [UIColor grayColor];

    3.去掉状态栏

    [[UIApplication sharedApplication] setStatusBarHidden:YES]; 

    //相关的属性

    //创建一个标签

    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 100, 40)];

    

    //1.背景颜色

    //两种:1.通过UIColor类封装的一些简单颜色方法。

   

  //2.通过一个方法,自己配置颜色(RGB(红,绿,蓝,透明度)国际标准)

    //注意:1.四个参数取值范围[0,1] 2.里面的值不要写整数,要写浮点数。 3.前三个参数的表示方式:[0,255]/255.  全1是白色  全0是黑色

    //label1.backgroundColor = [UIColor yellowColor];

    label1.backgroundColor = [UIColor colorWithRed:63./255. green:117./255. blue:1./255. alpha:1];

    

    //3.设置字体

    label1.text = @"学习";

    

    //4.设置字体颜色

    label1.textColor = [UIColor redColor];

    

    //5.字体大小

    //5.1普通的

    label1.font = [UIFont systemFontOfSize:20];

    //5.2设置加粗的

    label1.font = [UIFont boldSystemFontOfSize:30];

    

    //6.字体的样式

    label1.font = [UIFont fontWithName:@"menlo" size:15];

    //6.2查看字体

    NSLog(@"%@",[UIFont familyNames]);

    

    //7.字体的位置

    label1.textAlignment = NSTextAlignmentCenter;

    

    //8.阴影

    //8.1阴影颜色

    label1.shadowColor = [UIColor blueColor];

    //8.2阴影大小

    label1.shadowOffset = CGSizeMake(5, 5);

    

    //9.文字的自适应

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

    label2.text = @"阿迪分类卡还是短发舒服的;asdhfkajsdfa电话多少";        

    //9.1长,宽都是固定的。当width或height为0或SIZE_MAX的时候代表无限制

    label2.frame = CGRectMake(10, 200, 200, 0);    

    //9.2行数 默认是1,等于0时,代表无限行(任意行)

    label2.numberOfLines = 0;

    //9.3.文字有多大,范围就有多大

    [label2 sizeToFit];

    //获取label的高度

    //注意:获取值的大小要与开始创建时给定的大小保持一致

     CGSize size1 = [label2 sizeThatFits:CGSizeMake(200, 0)];

 ---------------UIButton-----------------

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];

  按钮样式:UIButtonTypeSystem 是iOS7.0之后的代表系统的按钮样式

                UIButtonTypeRoundedRect (圆角矩形)是iOS7.0以前在一直使用的系统样式

  //UIControlStateNormal 正常状态

    //UIControlStateHighlighted 高亮状态

    //UIControlStateSelected 选中状态 

   [button1 setTitle:@"点我" forState:UIControlStateNormal];

    button1.selected = NO;------未选中状态

  设置标题

    [button1 setTitle:@"选中我了" forState:UIControlStateSelected];

   设置位置

    button1.frame = CGRectMake(10, 40, 100, 40);

   执行方法

    [button1 addTarget:self action:@selector(clickedButton:) forControlEvents:UIControlEventTouchUpInside];

 ///自定义按钮

  UIButtonTypeCustom:自定义类型的按钮

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];

    1.位置

    button2.frame = CGRectMake(10, 100, 100, 40);

    

    2.设置显示文字

    [button2 setTitle:@"快点我" forState:UIControlStateNormal];

    2.2 文字颜色

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

    2.3文字大小

    [button2.titleLabel setFont:[UIFont systemFontOfSize:20]];

    

    高亮

    [button2 setTitle:@"我被点中了" forState:UIControlStateHighlighted];

    [button2.titleLabel setFont:[UIFont systemFontOfSize:5]];

    

    //位置

    //top:到顶部距离  left到左边距离  botton;到底部距离 right:到右边的距离

    UIEdgeInsets edgeInset = UIEdgeInsetsMake(0, 0, 5, 5);

    [button2 setTitleEdgeInsets:edgeInset];

 

    [button2.titleLabel setTextAlignment:NSTextAlignmentLeft];

    button2.backgroundColor = [UIColor yellowColor];

    

    //3.设置按钮的圆角  (深一点的知识)

    //layer:层 它是按钮上面的一个属性, 可以通过设置layer,达到设置按钮圆角的目的

    [button2.layer setMasksToBounds:YES];//是否可以设置圆角

    [button2.layer setCornerRadius:10];//设置半径

    [button2.layer setBorderWidth:5];//设置边框的宽度

    

    //4.背景(会将整个的按钮填满)

    button2.backgroundColor = [UIColor grayColor];

    //图片的对象,保存图片

    UIImage *image = [UIImage imageNamed:@"back.png"];

    [button2 setBackgroundImage:image forState:UIControlStateNormal];

    

    //5.设置图片

    UIImage *image1 = [UIImage imageNamed:@"logo.png"];    

    [button2 setImage:image1 forState:UIControlStateNormal];

    

    //点击按钮触发事件

    //target:响应方法的对象

    //action:响应的方法

    //UIControlEventTouchUpInside:点下抬起的时候

    [button2 addTarget:self action:@selector(clickedButton:) forControlEvents:UIControlEventTouchUpInside];

 

posted on 2014-12-30 11:26  溜逗~~  阅读(164)  评论(0编辑  收藏  举报

导航