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数据库之服务器主从配置
目的 主要培养对分布式REDIS主从复制架构运用的能力.理解并掌握REPLICATION工作原理的同时,能独立配置Replication ,使数据库运行在主从架格上.针对主从复制架构的运用,着力掌握S ...
- WordPress新用户注册时提示“您的密码重设链接无效”
在使用Wordpress密码找回功能及新用户注册邮件中的重置密码链接时,Wordpress提示“您的密码重设链接无效,请在下方请求新链接.”.“该key似乎无效”.“invalid key”. 这个其 ...
- MySql一个生产死锁案例分析
接到上级一个生产环境MySQL死锁日志信息文件,需要找出原因并解决问题.我将死锁日志部分贴出如下: 在mysql中使用命令:SHOW ENGINE INNODB STATUS;总能获取到最近一些问题信 ...
- spring5 源码深度解析----- 创建AOP代理之获取增强器
在上一篇的博文中我们讲解了通过自定义配置完成了对AnnotationAwareAspectJAutoProxyCreator类型的自动注册,那么这个类到底做了什么工作来完成AOP的操作呢?首先我们看看 ...
- 快学Scala 第十二课 (抽象类, 抽象字段, 提前定义)
抽象类: Scala 抽象类中,抽象方法不需要使用abstract. 在子类中重写超类抽象方法时,不需要使用override. abstract class Person { def say(s: S ...
- Java-Thread00之多线程知识准备
------  ...
- Java 添加、修改、读取、删除PPT备注
概述 幻灯片中的备注信息是只提供给幻灯片演讲者观看的特定内容,在演讲者放映幻灯片时,备注信息可给演讲者提供讲解思路,起到辅助讲解的作用.本文将通过Java程序来演示如何操作PPT幻灯片中的备注信息,要 ...
- 全球首个开放应用模型 OAM 开源 | 云原生生态周报 Vol. 23
作者 | 临石.元毅.冬岛.衷源.天元 业界要闻 全球首个开放应用模型 OAM 开源 2019 年 10 月 17 日,阿里巴巴合伙人.阿里云智能基础产品事业部总经理蒋江伟(花名:小邪)在 Qcon ...
- UDP方式的传输
UDP 部分内容需要查文档学习,我们需要了解下面的两个类:java.net.DatagramSocket和java.net.DatagramPacket java.net.DatagramSocket ...
- Python之random模块和time模块
1.random()模块的使用 import random x = random.random() y = random.random() print(x,y*10) #random.random ...