oc基本控件
(一)添加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基本控件的更多相关文章
- OC常用控件封装
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface CreateUI : NSObject ...
- ios学习笔记图片+图片解释(c语言 oc语言 ios控件 ios小项目 ios小功能 swift都有而且笔记完整喔)
下面是目录其中ios文件夹包括了大部分ios控件的介绍和演示,swift的时完整版,可以学习完swift(这个看的是swift刚出来一周的视频截图,可能有点赶,但是完整),c语言和oc语言的也可以完整 ...
- OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加,连减,连除,连乘)
OC中使用UI自己定义控件实现计算器的设计(版本号1简单的加减乘除,连加.连减,连除,连乘) #import <UIKit/UIKit.h> @interface ViewControll ...
- iOS开发——UI高级OC篇&自定义控件之调整按钮中子控件(图片和文字)的位置
自定义控件之调整按钮中子控件(图片和文字)的位置 其实还有一种是在storyBoard中实现的,只需要设置对应空间的左右间距: 这里实现前面两种自定义的方式 一:imageRectForContent ...
- JS与APP原生控件交互
"热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...
- iOS-UI-UI控件概述
以下列举一些在开发中可能用得上的UI控件: IBAction和IBOutlet,UIView 1 @interface ViewController : UIViewController 2 3 @p ...
- Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例
看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...
- Label控件如何根据字符串自定义大小
一.. this.label_Msg.AutoSize = false; //设置label空件不能自动大小 二.. 用代码控制label控件的大小 1.根据字符串.label的宽度 计算字符串的面 ...
- cocos2d-x视频控件VideoPlayer的用户操作栏进度条去除(转载)
目前遇到两个问题: (1)视频控件移除有问题,会报异常. (2)视频控件有用户操作栏,用户点击屏幕会停止视频播放. 对于第一个问题,主要是移除控件时冲突引起的,目前简单处理是做一个延时处理,先stop ...
随机推荐
- Redis 5.0 redis-cli --cluster help说明
背景: Redis Cluster 在5.0之后取消了ruby脚本 redis-trib.rb的支持(手动命令行添加集群的方式不变),集合到redis-cli里,避免了再安装ruby的相关环境.直接使 ...
- 性能优化:虚拟列表,如何渲染10万条数据的dom,页面同时不卡顿
列表大概有2万条数据,又不让做成分页,如果页面直接渲染2万条数据,在一些低配电脑上可能会照成页面卡死,基于这个需求,我们来手写一个虚拟列表 思路 列表中固定只显示少量的数据,比如60条 在列表滚动的时 ...
- git 查看分支
1.查看本地分支 git branch 2.查看所有分支 git branch -a 2.查看所有分支及对应版本信息 git branch -va
- 【SQL server初级】数据库性能优化一:数据库自身优化(大数据量)
数据库优化包含以下三部分,数据库自身的优化,数据库表优化,程序操作优化.此文为第一部分 数据库性能优化一:数据库自身优化 优化①:增加次数据文件,设置文件自动增长(粗略数据分区) 1.1:增加次数据文 ...
- Java基础学习笔记(五) - 常用的API
API介绍 概念:API 即应用编程程序接口.Java API是JDK中提供给我们使用的类说明文档,这些类将底层的代码实现封装.无需关心这些类是如何实现,只需要学习如何使用. 使用:通过API找到需要 ...
- js数组和表的基本操作
数组 var v = [3, 6, "hello"]; console.log(v.length); 数组的遍历1 function ss() { for (var i = 0; ...
- asp.net core learn
.NET Core WebApi RESTful规范 RESTful API 最佳实践 理解RESTful架构 接口版本控制 Support multiple versions of ASP.NET ...
- KafkaStream低级别API
开发者可以通过Processor接口来实现自己的自定义处理逻辑.接口提供了Process和Punctuate方法. 其中:Process方法用于处理接受到的消息 Punctuate方法指定时间间隔周期 ...
- Java线程池的底层实现与使用
前言 在我们进行开发的时候,为了充分利用系统资源,我们通常会进行多线程开发,实现起来非常简单,需要使用线程的时候就去创建一个线程(继承Thread类.实现Runnable接口.使用Callable和F ...
- Redis单线程架构以及工作方式
一.单线程模型 Redis客户端对服务端的每次调用都经历了发送命令,执行命令,返回结果三个过程.其中执行命令阶段,由于Redis是单线程来处理命令的,所有每一条到达服务端的每一条到达服务端的命令都不会 ...