(一)添加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. idea springBoot 配置devtools实现热部署

    1.pom文件依赖引入 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...

  2. PSSH工具

    目录 PSSH工具 参考 PSSH工具的介绍 PSSH工具的使用 PSSH工具

  3. vue中"‘webpack-dev-server’不是内部或外部命令,也不是可运行的程序"的报错

    在vue项目中发现了这个报错  解决办法将项目里的“node_modules”文件夹删除,然后重新运行cnpm install

  4. API文档注释 Javadoc

    阅读API文档 JDK包结构 JDK包是由sun开发的一组已经实现的类库,.JDK根据提供的功能不同,将类库划分为若干个包,比如用于操作输入输出的  java.io包,java程序语言设计基础类的   ...

  5. Tomcat源码分析二:先看看Tomcat的整体架构

    Tomcat源码分析二:先看看Tomcat的整体架构 Tomcat架构图 我们先来看一张比较经典的Tomcat架构图: 从这张图中,我们可以看出Tomcat中含有Server.Service.Conn ...

  6. JDBC访问数据库的基本步骤

    加载驱动 通过DriverManager对象获取连接对象Connection 通过连接对象获取会话 通过会话进行数据的增删改查,封装对象 关闭资源

  7. JS中的排序算法-冒泡排序解析

    冒泡排序算法 例子:10,8,9,6,4,20,5  从小到大排序 第一轮  1)10>8  交换数据 得到:8,10,9,6,4,20,5 2)10>9  交换数据 得到:8,9,10, ...

  8. deferred对象和promise对象(一)

    个人认为阮一峰老师讲的关于deferred对象是最容易理解的. deferred对象是jquery的回调函数解决方案.解决了如何处理耗时操作的问题,对那些操作提供了更好的控制,以及统一的编程接口. d ...

  9. AWVS安全渗透扫描

    1.打开软件,点击New Scan 2.在website url中输入被扫描的网址,点击next 3.在scanning profile中选择测试的漏洞类型,默认选择default(默认) 在scan ...

  10. Java编程思想——第17章 容器深入研究 读书笔记(四)

    九.散列与散列码 HashMap使用equals()判断当前的键是否与表中存在的键相同. 正确的equals()方法需满足一下条件: 1)自反性.x.equals(x) 是true; 2)对称性.x. ...