oc基本控件

1.添加UIWindow

UIWindow *window1=[[UIWindow alloc] init];
    //window.frame=CGRectMake(10, 470, 100, 30);
    window1.backgroundColor=[UIColor redColor];
    window1.hidden=No;
    
    [self.view addSubview:window1];

2.添加label

//label
    UILabel *label=[[UILabel alloc] init];
    label.frame=CGRectMake(10, 10, 100, 30);
    label.textColor=[UIColor redColor];
    label.backgroundColor=[UIColor greenColor];
    label.text=@"lable";
    label.textAlignment=1;
 
    [self.view addSubview:label];

3.添加button

//button按钮
    UIButton *button=[[UIButton alloc] init];
    button.frame=CGRectMake(10, 50, 100, 30);
    button.backgroundColor=[UIColor blueColor];
    button.tag=100;
    [button setTitle:@"button" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button setTintColor:[UIColor greenColor]];
    button.showsTouchWhenHighlighted=YES;//高亮效果
    //[button setBackgroundColor:[UIColor redColor]];
    //[button setBackgroundImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>]
    //添加点击事件,若要传参数则事件后加“:”
    [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchDown];
    
    [self.view addSubview:button];

4.添加uiimageview

//uiimage+uiimageview
    UIImage *image=[UIImage imageNamed:@"Gaode.jpg"];
    UIImageView *imageView=[[UIImageView alloc] init];
    imageView.frame=CGRectMake(10, 90, 100, 100);
    [imageView setImage: image];
    imageView.contentMode=UIViewContentModeScaleToFill;
    imageView.alpha=1;
    //self.view.backgroundColor=[UIColor colorWithPatternImage:image];
    
    //播放序列帧 10帧
//    NSMutableArray *images=[[NSMutableArray alloc] init];
//
//    for(int i=0;i<10;i++)
//    {
//        UIImage *aniImage=[UIImage imageNamed:@"相关名字"];
//        [images addObject:aniImage];
//    }
//
//    imageView.animationImages=images;
//    imageView.animationDuration=1;//播放总时间
//    imageView.animationRepeatCount=5;//播放次数
//    [imageView startAnimating];//start play
    
    [self.view addSubview:imageView];

5.添加slider

//slider
    UISlider *slider=[[UISlider alloc] init];
    slider.frame=CGRectMake(10, 210, 100, 5);
    slider.backgroundColor=[UIColor redColor];
    slider.value=0.5;
    [slider addTarget:self action:@selector(onSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    //设置最大值时的图片
    //slider.maximumValueImage = [UIImage imageNamed:@"Gaode.jpg"];
    //设置最小值时的图片
    //slider.minimumValueImage = [UIImage imageNamed:@"Gaode.jpg"];
   
    [self.view addSubview:slider];

6.添加switch

//switch
    UISwitch *mySwitch=[[UISwitch alloc] init];
    mySwitch.frame=CGRectMake(10, 240, 100, 30);
    [mySwitch addTarget:self action:@selector(onSwitchChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:mySwitch];
    
    //uiview
    UIView *view=[[UIView alloc] init];
    view.frame=CGRectMake(10, 280, 100, 100);
    view.backgroundColor=[UIColor redColor];
    
    [self.view addSubview:view];

7.视图uiview

//uiview
    UIView *view=[[UIView alloc] init];
    view.frame=CGRectMake(10, 280, 100, 100);
    view.backgroundColor=[UIColor redColor];
    
    [self.view addSubview:view];
    
    UIView *subView=[[UIView alloc] init];
    subView.frame=CGRectMake(0, 10, 100, 50);
    subView.backgroundColor=[UIColor blueColor];
    [view addSubview:subView];
    
//    [self.view sendSubviewToBack:subView];//把subView设置为最底层
//    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];//交换连个view
 //   [self.view bringSubviewToFront:subView];//把subView设置为最上层
//    [self.view insertSubview:subView atIndex:0];//把subView插入到0位置

8.文本输入框uitextfield

//uitextfield
    UITextField *textField=[[UITextField alloc] init];
    textField.frame=CGRectMake(10, 390, 100, 30);
    textField.placeholder=[[NSString alloc] initWithFormat:@"input Field"];
    
    //.h中添加UITextField委托(ViewController : UIViewController,UITextFieldDelegate,并在.m中实现相关方法
    //[textField becomeFirstResponder];//设置第一相应对象,会相应appDelegate中添加的UITextFieldDelegate委托
    [self.view addSubview:textField];

9.uicontrol

UIControl *control=[[UIControl alloc] init];
    control.frame=CGRectMake(10, 430, 100, 30);
    control.backgroundColor=[UIColor blueColor];
    [control addTarget:self action:@selector(controlEvent) forControlEvents:UIControlEventTouchDown];
    
    [self.view addSubview:control];
-(void) controlEvent
{
    NSLog(@"control event");
}

-(void) onSwitchChanged:(UISwitch *)mySwitch
{
    if(mySwitch.on==YES)
    {
        NSLog(@"switch value is Yes");
    }
    else
    {
        NSLog(@"switch value is No");
    }
}

-(void) onSliderValueChanged:(id)sender
{
    UISlider *sld=(UISlider*)sender;
    NSLog(@"slider value is %f",sld.value);
}

-(void) buttonEvent:(id) sender
{
    UIButton *btn=(UIButton*) sender;
    NSLog(@"button with tag_%ld clicked",btn.tag);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值