IOS UI 第六篇:基本UI
加两个UI模块
{
[self begin1];
[self begin2];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)begin1{
UIActivityIndicatorView *viView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
viView.center = CGPointMake(160, 300);
viView.color = [UIColor blueColor];
viView.hidesWhenStopped = NO;
[viView startAnimating];
[viView stopAnimating];
[self.view addSubview:viView];
}
-(void)begin2{
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
mySwitch.onTintColor = [UIColor redColor];
mySwitch.on = NO;
[mySwitch setOn:YES animated:YES];
[mySwitch addTarget:self action:@selector(onButton:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch];
}
-(void)onButton:(id)sender{
NSLog(@":::%@", sender);
UISwitch *sw = sender;
if(sw.on) NSLog(@"ON");
else NSLog(@"OFF");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
if(textField.text.length >= 6 && !range.length)
return NO;
return YES;
}
NSLog(@"%d-%d-%d",range.length, range.location, textField.text.length);
if (textField == self.nameTextField) {
if(textField.text.length >= 6 && !range.length)
return NO;
return YES;
}
if (textField == self.passwordTextField){
if(textField.text.length >= 4 && !range.length)
return NO;
return YES;
}
return YES;
}
//将输入框取消第一响应者,键盘就睡自动收回
[self.nameTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
//在销毁的时候将自己在通知中心中移除
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
NSLog(@"textFiled 键盘的return键被点击");
[textField resignFirstResponder];
NSLog(@"开始搜索!!!");
return YES;
}
@property (strong, nonatomic) IBOutlet UIView *subView;
@property (nonatomic, assign)float red;
@property (nonatomic, assign)float blue;
@property (nonatomic, assign)float green;
@property (nonatomic, assign)float alpha;
@property (weak, nonatomic) IBOutlet UILabel *redLabel;
@property (weak, nonatomic) IBOutlet UILabel *greenLabel;
@property (weak, nonatomic) IBOutlet UILabel *blueLabel;
@property (weak, nonatomic) IBOutlet UILabel *alphaLabel;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_redLabel.text = [NSString stringWithFormat:@"%%50"];
_blueLabel.text = [NSString stringWithFormat:@"%%50"];
_greenLabel.text = [NSString stringWithFormat:@"%%50"];
_alphaLabel.text = [NSString stringWithFormat:@"%%50"];
_red = _green = _blue = _alpha = 0.5;
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
// Do any additional setup after loading the view, typically from a nib.
UISlider *slide = [[UISlider alloc] initWithFrame:CGRectMake(10, 300, 300, 60)];
slide.minimumValue = 0;
slide.maximumValue = 1;
[slide setValue:0.5 animated:YES];
[slide addTarget:self action:@selector(onSliderChange:) forControlEvents:UIControlEventValueChanged];
//[self.view addSubview:slide];
}
-(void)onSliderChange:(id)sender{
NSLog(@"slider:%@", sender);
UISlider *slider = sender;
self.subView.alpha = slider.value;
}
- (IBAction)blueSlider:(id)sender {
UISlider *slider = sender;
_blue = slider.value;
_blueLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)greenSlider:(id)sender {
UISlider *slider = sender;
_green = slider.value;
_greenLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)redSlider:(id)sender {
UISlider *slider = sender;
_red = slider.value;
_redLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)alphaSlider:(id)sender {
UISlider *slider = sender;
_alpha = slider.value;
_alphaLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
{
[self begin1];
[self begin2];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)begin1{
UIActivityIndicatorView *viView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
viView.center = CGPointMake(160, 300);
viView.color = [UIColor blueColor];
viView.hidesWhenStopped = NO;
[viView startAnimating];
[viView stopAnimating];
[self.view addSubview:viView];
}
-(void)begin2{
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
mySwitch.onTintColor = [UIColor redColor];
mySwitch.on = NO;
[mySwitch setOn:YES animated:YES];
[mySwitch addTarget:self action:@selector(onButton:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch];
}
-(void)onButton:(id)sender{
NSLog(@":::%@", sender);
UISwitch *sw = sender;
if(sw.on) NSLog(@"ON");
else NSLog(@"OFF");
}
UIView *redView;
CGPoint beginPoint;
BOOL canMove;
BOOL mark;
}
- (void)viewDidLoad
{
[super viewDidLoad];
redView=[[UIView alloc]initWithFrame:CGRectMake(-320, 0, 320, 480)];
redView.backgroundColor=[UIColor redColor];
[self.view addSubview:redView];
mark = 0;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark--
#pragma mark touch事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//任意取出一个touch对象
UITouch *touch = touches.anyObject;
beginPoint = [touch locationInView:self.view];
NSLog(@"mark = %d", mark);
if(mark == 0){
if (beginPoint.x<20) {
canMove=YES;
}else{
canMove=NO;
}
}
if(mark){
if (beginPoint.x]]]]>300) {
canMove=YES;
}else{
canMove=NO;
}
}
NSLog(@"触摸开始 %f,%f---",beginPoint.x,beginPoint.y);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = touches.anyObject;
CGPoint movePoint = [touch locationInView:self.view];
NSLog(@"触摸滑动 %f",movePoint.x-beginPoint.x);
if (canMove && mark == 0) {
redView.frame=CGRectMake(-320+movePoint.x-beginPoint.x, 0, 320, 480);
}
if( canMove && mark == 1){
redView.frame=CGRectMake(movePoint.x - 320 , 0, 320, 480);
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"触摸结束");
UITouch *touch = touches.anyObject;
CGPoint endPoint = [touch locationInView:self.view];
if(mark == 0){
if ((endPoint.x-beginPoint.x)>200) {
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(0, 0, 320, 480);
}];
mark = 1;
}else{
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(-320, 0, 320, 480);
}];
}
}
else if(mark == 1){
NSLog(@"duanyulei");
if ((320 - endPoint.x)<20) {
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(-320, 0, 320, 480);
}];
mark = 0;
}else{
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(0, 0, 320, 480);
}];
}
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"触摸取消");
}
- (IBAction)showAlertView:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *showActionSheet;
- (IBAction)showActionSheet:(id)sender;
@end
@implementation QFViewController{
UIAlertView *alertView;
UIActionSheet *actionSheet;
}
- (void)viewDidLoad
{
[super viewDidLoad];
alertView=[[UIAlertView alloc]initWithTitle:@"通知" message:@"明天礼拜五了,大家晚上多多努力,争取在放假前把项目上架。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil,nil];
actionSheet=[[UIActionSheet alloc]initWithTitle:@"你确定删除么?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showAlertView:(id)sender {
[alertView show];
}
- (IBAction)showActionSheet:(id)sender {
[actionSheet showInView:self.view];
}
#pragma mark--
#pragma mark UIAlertView代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"点击了第%d个按键",buttonIndex);
switch (buttonIndex) {
case 0:
break;
default:
break;
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"点击了第%d个按键",buttonIndex);
switch (buttonIndex) {
case 0:
break;
default:
break;
}
}
IOS UI 第六篇:基本UI的更多相关文章
- IOS设计模式第六篇之适配器设计模式
版权声明:原创作品,谢绝转载!否则将追究法律责任. 那么怎么使用适配器设计模式呢? 这个之前提到的水平滚动的视图像这样: 为了开始实现他,我们创建一个新的继承与UIView的HorizontalScr ...
- IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上 - (void)viewDidLoad{ [super viewDidLoad]; UIScrollView *scrollView = [[U ...
- iOS进阶指南试读之UI篇
iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...
- 四核驱动的三维导航—淘宝新UI(设计篇)
前面有一篇博客说到了淘宝UWP的"四核驱动的三维导航—淘宝新UI(需求分析篇)",花了两周的时间实现了这个框架,然后又陆陆续续用了三周的时间完善它. 多窗口导航,与传统的导航方式的 ...
- 游戏模块分析总结(2)之UI、操作篇
转自:http://www.gameres.com/309812.html 游戏模块分析总结(2)之UI.操作篇 发布者: wuye | 发布时间: 2014-12-12 15:03| 评论数: 0 ...
- WPF案例 (六) 动态切换UI布局
原文:WPF案例 (六) 动态切换UI布局 这个Wpf示例对同一个界面支持以ListView或者CardView的布局方式呈现界面,使用控件ItemsControl绑定数据源,使用DataTempla ...
- 环信 之 iOS 客户端集成四:集成UI
在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...
- WPF 精修篇 非UI进程后台更新UI进程
原文:WPF 精修篇 非UI进程后台更新UI进程 <Grid> <Grid.RowDefinitions> <RowDefinition Height="11* ...
- 第六章 consul UI
1.建立三个consul节点(一个server+两个client) 具体的过程见http://www.cnblogs.com/java-zhao/p/5375132.html 1)在终端下启动vagr ...
随机推荐
- sql小总结
---------------------------------------------------------------------------------------------------- ...
- PHP从零单排(十八)图像处理
1.打开现有的图像 <?php header("Content-type:image/jpeg"); $img=imagecreatefromjpeg("cc.jp ...
- javascript系列之this
原文:javascript系列之this 引言 在这篇文章里我们将会讨论与执行上下文直接相关的更多细节.讨论的主题就是this关键字.实践证明,这个主题是足够难的并且在不同的执行上下文中判定this的 ...
- kobject_create_and_add
本文来源于源linux 3.14.3版本号/lib/kobject.c文件 /** * kobject_create_and_add - 动态地创建kobject结构和寄存器sysfs * * ...
- 离github在导入dubbo工程
dubbo移动到github目前已经有一些时间,我们可能根本不习惯使用github.因此,我们仍然使用以前的版本号. 由于某些原因.阿里下载前关闭.在这里给大家提供一个私有地址: 链接:http:// ...
- linux_设置开机自启动程序脚本
设置开机自启动
- 【百度地图API】如何根据摩卡托坐标进行POI查询,和计算两点距离
原文:[百度地图API]如何根据摩卡托坐标进行POI查询,和计算两点距离 摘要: 百度地图API有两种坐标系,一种是百度经纬度,一种是摩卡托坐标系.在本章你将学会: 1.如何相互转换这两种坐标: 2. ...
- Android:仿手机QQ朋友动态ListView
1.介绍: 使用此博客XListView模仿Android版本QQ朋友动态ListView效果.效果如下面的截图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZ ...
- 详解linux vi命令用法
vi是所有UNIX系统都会提供的屏幕编辑器,它提供了一个视窗设备,通过它可以编辑文件.当然,对UNIX系统略有所知的人,或多或少都觉得vi超级难用,但vi是最基本的编辑器,所以希望读者能好好把它学起来 ...
- 如何设置Installshield中 feature的选中状态
原文:如何设置Installshield中 feature的选中状态 上一篇: 使用strtuts2的iterator标签循环输出二维数组之前一直有筒子问如何设置Installshield中 feat ...