博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oc基本控件
阅读量:5323 次
发布时间:2019-06-14

本文共 4893 字,大约阅读时间需要 16 分钟。

(一)添加UIWindow

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

(二)添加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];

(三)添加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];

(四)添加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];

(五)添加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];

(六)添加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];

(七)试图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位置

(八)文本输入框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];

(九)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);}

 

转载于:https://www.cnblogs.com/llstart-new0201/p/9651717.html

你可能感兴趣的文章
TQ2440之中断
查看>>
MySQL 触发器简单实例
查看>>
codeforces 712A. Memory and Crow
查看>>
Latex Undefined control sequence. ...\bm
查看>>
MySQL------报错Access denied for user 'root'@'localhost' (using password:NO)解决方法
查看>>
车牌识别LPR(三)-- LPR系统整体结构
查看>>
log4j异常:WARN No appenders could be found for logger
查看>>
新手村之顺序与分支
查看>>
4.秋招复习简单整理之java支持多继承吗?
查看>>
BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊(LCT)
查看>>
Linux分区问题
查看>>
封装的ajax
查看>>
WP8 学习 Onnavigatedto和OnnavigatedFrom的区别
查看>>
java中Comparator接口的用法
查看>>
《Effective C#》读书笔记——条目3:推荐使用is或as而不是强制转换类型<C#语言习惯>...
查看>>
开发积累—泛型工具类
查看>>
iOS项目开发实战——制作视图的缩放动画
查看>>
关于在jquery动态修改css,html中,mouseenter,mouseleave,click等方法失效的处理
查看>>
[翻译] java NIO 教程---介绍
查看>>
Java开发小技巧(一)
查看>>