(一)添加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. [python]兔子问题,斐波那契数列 递归&非递归

    假设一对幼年兔子需要一个月长成成年兔子,一对成年兔子一个月后每个月都可以繁衍出一对新的幼年兔子(即兔子诞生两个月后开始繁殖).不考虑死亡的情况,问第 N 个月时共有多少对兔子? 结果前几个月的兔子数量 ...

  2. python爬取哦漫画

    import requests from lxml import etree from bs4 import BeautifulSoup import os from selenium import ...

  3. Vue-cli连接mysql

    本文把前后台一起串起来,前端使用vue-cli后台用nodejs连接数据库,vue-cli请求接口其数据是来自于mysql数据. 一.vue-cli请求接口部分 <template> &l ...

  4. 使用 .NET Core 3.0 的 AssemblyLoadContext 实现插件热加载

    一般情况下,一个 .NET 程序集加载到程序中以后,它的类型信息以及原生代码等数据会一直保留在内存中,.NET 运行时无法回收它们,如果我们要实现插件热加载 (例如 Razor 或 Aspx 模版的热 ...

  5. Fast Earth - 文本 绘制,如何实现三维空间中绘制屏幕大小的文字?

    如题:先上一张图,在说是如何实现的 实现上图效果,有如下三种方式: 1. 屏幕坐标绘制点要素,即将经纬度坐标转换成屏幕坐标方式绘制,大多数GIS系统都是采用这种方式: 优点:实现方式简单,效果较好 缺 ...

  6. 再探vue

    1. vue项目搭建 搭建vue环境需要安装node软件,node是由c++编写而成,主要运行js文件或者js代码的,安装node会自动安装一个管理器叫npm,建议换源下载,国外的网站较慢(比如cnp ...

  7. texlive支持中文的简单方法

    1.确保tex文件的编码方式是UTF-8, 2.在文档开始处添加一行命令即可,即 \usepackage[UTF8]{ctex} , 如下所示: \documentclass{article} \us ...

  8. poll(2) 源码分析

    poll(2) poll(2) 系统调用的功能和 select(2) 类似:等待一个文件集合中的文件描述符就绪进行I/O操作. 使用 实现 select(2) 的局限性: 关注的文件描述符集合大小最大 ...

  9. 分享一个移动端rem布局的适配mixin

    /*================================================================ 以下为基于ip5 宽度320做的适配,标准html{font-si ...

  10. A-06 最小角回归法

    目录 最小角回归法 一.举例 二.最小角回归法优缺点 2.1 优点 2.2 缺点 三.小结 更新.更全的<机器学习>的更新网站,更有python.go.数据结构与算法.爬虫.人工智能教学等 ...