UIView UILabel UITextField UIButton UIImageView 常用属性

9 篇文章 0 订阅

 


  UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(20,40,80,30)];

//    背景颜色

    label.backgroundColor = [UIColorgreenColor];

//    添加文字

    label.text =@"神剑";

//    文字对齐方式

    label.textAlignment =NSTextAlignmentCenter;

//    文字颜色

    label.textColor = [UIColorblackColor];

//    字体

    label.font = [UIFontsystemFontOfSize:20];

//    设置文字行数

    label.numberOfLines =2;

//    设置边框圆角

    label.layer.cornerRadius =5;

//    设置边框 宽度为3

    label.layer.borderWidth =3;

//    边框颜色

    label.layer.borderColor = [UIColorblueColor].CGColor;

//    设置阴影

    label.shadowColor = [UIColorredColor];

//    阴影大小

    label.shadowOffset =CGSizeMake(2.0,2.0);

//    文字可变 默认为YES

    label.enabled =NO;

//    用户交互

    label.userInteractionEnabled =YES;

    

    label.transform = CGAffineTransformMakeRotation(0.5);     //设置label的旋转角度


    [_windowaddSubview:label];

    [labelrelease];

    

    

   UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(40,90,80,30)];

    view.backgroundColor = [UIColorgreenColor];

//    设置中心点

//    view.frame = CGRectMake(0, 0, 80, 30);

//    view.center = CGPointMake(100, 100);

//    隐藏

    view.hidden =YES;

//    透明度

    view.alpha =0.5;// 0.1 ~ 1

    

    [_windowaddSubview:view];

//    视图置顶

    [_windowbringSubviewToFront:view];

//    视图置底

    [_windowsendSubviewToBack:view];

//    交换两个视图

//    [_window exchangeSubviewAtIndex:<#(NSInteger)#> withSubviewAtIndex:<#(NSInteger)#>]

//    插入视图

//    _window insertSubview:<#(UIView *)#> atIndex:<#(NSInteger)#>

//    移除视图

    [view removeFromSuperview];

//    判断一个视图是否是另一个的子视图

    [view isDescendantOfView:_window];

    

    [viewrelease];

    

    

   UITextField *textField = [[UITextFieldalloc]initWithFrame:CGRectMake(0,0,200,40)];


//    提示输入 textField输入后消失

    textField.placeholder =@"请输入";

//    设置边框样式

    textField.borderStyle =UITextBorderStyleRoundedRect;

//    右侧清除按钮

    textField.clearButtonMode =UITextFieldViewModeWhileEditing;

//    隐藏输入信息一般用在密码输入

    textField.secureTextEntry =YES;

    

//    Button初始化需要先选择样式

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

//    设置frame

    button.frame =CGRectMake(20,20,50,50);

//    设置背景颜色

    button.backgroundColor = [UIColorblueColor];

//    设置按钮标题

    [button setTitle:@"按钮"forState:UIControlStateNormal];

//    设置标题颜色(标题默认为蓝色)

    [button setTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];

//    设置标题字体大小

//                            加粗字体为 boldSystemFontOfSize

    [button.titleLabelsetFont:[UIFontsystemFontOfSize:20]];

    

              button.titleEdgeInsets = UIEdgeInsetsMake(71, -button.titleLabel.bounds.size.width-50, 0, 0);
             //设置title在button上的位置(上top,左left,下bottom,右right)  
              button.imageEdgeInsets = UIEdgeInsetsMake(5,13,21,button.titleLabel.bounds.size.width);
              //设置image在button上的位置(上top,左left,下bottom,右right)这里可以写负值,对上写-5,那么image就象上移动5个像素  
      


//    button 点击事件

    [button addTarget:selfaction:@selector(buttonDidPress:)forControlEvents:UIControlEventTouchUpInside];

    


- (void)buttonDidPress:(UIButton *) button {

    button.backgroundColor = [UIColor greenColor];

}


  UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];

    //    设置图像 UIImage

    //   在设置图片的时候名称+后缀 一定要全部写上,只有.png可以忽略不写

    imageView.image = [UIImageimageNamed:@"/Users/dllo/Desktop/[(ITVEW13E5N}HL~[4Q$4%8.jpg"];

    //     填充方式

    imageView.contentMode =UIViewContentModeScaleAspectFill;

    //     圆角

    imageView.layer.masksToBounds =YES;

    imageView.layer.cornerRadius =50;


    




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值