(一)添加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(, , , );
label.textColor=[UIColor redColor];
label.backgroundColor=[UIColor greenColor];
label.text=@"lable";
label.textAlignment=; [self.view addSubview:label];

(三)添加button

    //button按钮
UIButton *button=[[UIButton alloc] init];
button.frame=CGRectMake(, , , );
button.backgroundColor=[UIColor blueColor];
button.tag=;
[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(, , , );
[imageView setImage: image];
imageView.contentMode=UIViewContentModeScaleToFill;
imageView.alpha=;
//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(, , , );
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(, , , );
[mySwitch addTarget:self action:@selector(onSwitchChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch]; //uiview
UIView *view=[[UIView alloc] init];
view.frame=CGRectMake(, , , );
view.backgroundColor=[UIColor redColor]; [self.view addSubview:view];

(七)试图uiview

    //uiview
UIView *view=[[UIView alloc] init];
view.frame=CGRectMake(, , , );
view.backgroundColor=[UIColor redColor]; [self.view addSubview:view]; UIView *subView=[[UIView alloc] init];
subView.frame=CGRectMake(, , , );
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(, , , );
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(, , , );
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);
}

oc基本控件的更多相关文章

  1. OC常用控件封装

    #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface CreateUI : NSObject ...

  2. ios学习笔记图片+图片解释(c语言 oc语言 ios控件 ios小项目 ios小功能 swift都有而且笔记完整喔)

    下面是目录其中ios文件夹包括了大部分ios控件的介绍和演示,swift的时完整版,可以学习完swift(这个看的是swift刚出来一周的视频截图,可能有点赶,但是完整),c语言和oc语言的也可以完整 ...

  3. OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加,连减,连除,连乘)

    OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加.连减,连除,连乘) #import <UIKit/UIKit.h> @interface ViewControll ...

  4. iOS开发——UI高级OC篇&自定义控件之调整按钮中子控件(图片和文字)的位置

    自定义控件之调整按钮中子控件(图片和文字)的位置 其实还有一种是在storyBoard中实现的,只需要设置对应空间的左右间距: 这里实现前面两种自定义的方式 一:imageRectForContent ...

  5. JS与APP原生控件交互

    "热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...

  6. iOS-UI-UI控件概述

    以下列举一些在开发中可能用得上的UI控件: IBAction和IBOutlet,UIView 1 @interface ViewController : UIViewController 2 3 @p ...

  7. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例

    看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...

  8. Label控件如何根据字符串自定义大小

    一.. this.label_Msg.AutoSize = false;  //设置label空件不能自动大小 二.. 用代码控制label控件的大小 1.根据字符串.label的宽度 计算字符串的面 ...

  9. cocos2d-x视频控件VideoPlayer的用户操作栏进度条去除(转载)

    目前遇到两个问题: (1)视频控件移除有问题,会报异常. (2)视频控件有用户操作栏,用户点击屏幕会停止视频播放. 对于第一个问题,主要是移除控件时冲突引起的,目前简单处理是做一个延时处理,先stop ...

随机推荐

  1. 自定义构建基于.net core 的基础镜像

    先说一个问题 首先记录一个问题,今天在用 Jenkins 构建项目的时候突然出现包源的错误: /usr/share/dotnet/sdk/2.2.104/NuGet.targets(114,5): e ...

  2. 对cpu与load的理解及线上问题处理思路解读

    前言 2019双11还有不到2个月就要到来了,大家也都知道服务器在大促期间由于流量的增加势必导致机器的cpu与load变高.因此趁着这个时机正好再好好学习.巩固一下cpu和load的概念,为双11做准 ...

  3. [Note] GNUstep on Windows

    1.下载与安装 www.gnustep.org/windows/installer.html 下载 GNUstep MSYS System GNUstep Core GNUstep Devel 并安装 ...

  4. 安装web3失败问题

    ① 首先可以先通过 npm cache verify 清理下缓存,在进行安装 ② 如果还是安装失败可以尝试 ---   npm install web3@^0.20.0  或者 npm install ...

  5. 文件/大文件上传功能实现(JS+PHP)全过程

    文件/大文件上传功能实现(JS+PHP) 参考博文:掘金-橙红年代 前端大文件上传 路漫漫 其修远 PHP + JS 实现大文件分割上传 本文是学习文件上传后的学习总结文章,从无到有实现文件上传功能, ...

  6. .netCore+Vue 搭建的简捷开发框架 (4)--NetCore 基础 -2

    上节中,我们初步的介绍了一下NetCore的一些基础知识,为了控制篇幅(其实也是因为偷懒),我将NetCore 基础分为两部分来写. 0.WebAPI 项目的建立 1..NetCore 项目执行(加载 ...

  7. java23种设计模式(一)工厂方法模式

    在说工厂方法模式之前,先了解一下简单工厂模式.工厂方法模式其实是在简单工厂上面做了一些增强. 简单工厂模式:有一个专门的类来生产其他类的实例,生产的这些实例有一个共同父类.这个跟我们的多态有一点像. ...

  8. Map集合(双列集合)

    Map集合(双列集合)Map集合是键值对集合. 它的元素是由两个值组成的,元素的格式是:key=value. Map集合形式:{key1=value1 , key2=value2 , key3=val ...

  9. 基于 Web 端 3D 地铁站可视化系统

    前言 工业互联网,物联网,可视化等名词在我们现在信息化的大背景下已经是耳熟能详,日常生活的交通,出行,吃穿等可能都可以用信息化的方式来为我们表达,在传统的可视化监控领域,一般都是基于 Web SCAD ...

  10. MVC路径无匹配或请求api版本过低时处理

    解决方案:RequestMappingHandlerMapping中重写handleNoMatch方法,springMVC和springboot中配置无区别. 另: 1.可搭配advice处理抛出的异 ...