加两个UI模块

 
- (void)viewDidLoad
{
    [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

 
TextField 限制密码数目:
 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

if(textField.text.length >= 6 && !range.length)
        return NO;
    return YES;
}

 
 
有多个TextField 则限制所指定的数目:
 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    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;
}
 
 
手势:
 
添加手势:
 
     UITapGestureRecognizer *tapGR;//添加单击手势
     tapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTap:)];
     [self.view addGestureRecognizer:tapGR];
     [self.view removeGestureRecognizer:tapGR];
 
 
-(void)onTap:(id)sender{
    //将输入框取消第一响应者,键盘就睡自动收回
    [self.nameTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}
 
-(void)dealloc{
    //在销毁的时候将自己在通知中心中移除
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
 
 
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"textFiled 键盘的return键被点击");
    [textField resignFirstResponder];
    NSLog(@"开始搜索!!!");
    return YES;
}
 
 
自己做一个小调色板(红色、蓝色、绿色、透明度):如图
 
 
代码:
 
@interface ViewController ()

@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];
}

 
 
按钮开关相应事件:
 
 
- (void)viewDidLoad
{
    [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");
}

 
 
触摸方法:
 
@implementation QFViewController{
    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(@"触摸取消");
}

 
 
 
警告和通知:
 
 
@interface QFViewController ()<UIAlertViewDelegate,UIActionSheetDelegate]]]]>
- (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的更多相关文章

  1. IOS设计模式第六篇之适配器设计模式

    版权声明:原创作品,谢绝转载!否则将追究法律责任. 那么怎么使用适配器设计模式呢? 这个之前提到的水平滚动的视图像这样: 为了开始实现他,我们创建一个新的继承与UIView的HorizontalScr ...

  2. IOS UI 第八篇:基本UI

    实现图片的滚动,并且自动停止在每张图片上     - (void)viewDidLoad{    [super viewDidLoad]; UIScrollView *scrollView = [[U ...

  3. iOS进阶指南试读之UI篇

    iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...

  4. 四核驱动的三维导航—淘宝新UI(设计篇)

    前面有一篇博客说到了淘宝UWP的"四核驱动的三维导航—淘宝新UI(需求分析篇)",花了两周的时间实现了这个框架,然后又陆陆续续用了三周的时间完善它. 多窗口导航,与传统的导航方式的 ...

  5. 游戏模块分析总结(2)之UI、操作篇

    转自:http://www.gameres.com/309812.html 游戏模块分析总结(2)之UI.操作篇 发布者: wuye | 发布时间: 2014-12-12 15:03| 评论数: 0 ...

  6. WPF案例 (六) 动态切换UI布局

    原文:WPF案例 (六) 动态切换UI布局 这个Wpf示例对同一个界面支持以ListView或者CardView的布局方式呈现界面,使用控件ItemsControl绑定数据源,使用DataTempla ...

  7. 环信 之 iOS 客户端集成四:集成UI

    在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...

  8. WPF 精修篇 非UI进程后台更新UI进程

    原文:WPF 精修篇 非UI进程后台更新UI进程 <Grid> <Grid.RowDefinitions> <RowDefinition Height="11* ...

  9. 第六章 consul UI

    1.建立三个consul节点(一个server+两个client) 具体的过程见http://www.cnblogs.com/java-zhao/p/5375132.html 1)在终端下启动vagr ...

随机推荐

  1. iOS 8中CLLocationManager及MKMapView showUserLocation失败的解决的方法

    用XCode 6编译的原来XCode 5.1.1写的程序时,发现原来写的CLLocationManager定位的代码以及MKmapView的showUserLocation失效.查了一下,XCode ...

  2. 几个更新(Update声明)查询方法

    积极 文化: 上的方法,数据库更新Update.的标准格式:Update 表名 set =值 where 条件只是依据数据的来源不同,还是有所差别的:  1.从外部输入这样的比較简单例:update ...

  3. linux_java_redis_postgresql_常用命令

     redis 常用语法telnet 192.168.18.210 6379keys *llen队列名称llen 队列名称 postgresql常用语法psql -h192.168.18.210 -Up ...

  4. 从头开始学JavaScript (九)——执行环境和作用域

    原文:从头开始学JavaScript (九)--执行环境和作用域 一.执行环境:定义了变量或者函数有权访问的其他数据,决定了它们各自的行为.每个执行环境都有与之关联的变量对象. 变量对象:保存着环境中 ...

  5. Meteor入门

    转载Meteor入门介绍   Meteor是什么 基于nodejs的实时web APP开发框架. Meteor能带来什么 简单的说,你可以用js搞定客户端.服务端的开发.另外,客户端.服务端的界限被极 ...

  6. 百度地图API 添加自定义标注 多点标注

    原文:百度地图API 添加自定义标注 多点标注 分四个文件 location.php map.css 图片 数据库 数据库配置自己改下 -------------------------------- ...

  7. 教你一步一步部署.net免费空间OpenShift系列之四------绑定域名、使用CDN加速

    很抱歉这几天没有时间,有人问我怎么绑定域名的问题也没有答复,下面进入正题,惊闻ASP.Net要开源了,难道.Net春天要来了?不废话,上回书说,部署完毕ASP.Net网站后,直接访问不能访问(嗯,众所 ...

  8. 深入理解C指针之一:初识指针

    原文:深入理解C指针之一:初识指针 简单来说,指针包含的就是内存地址.理解指针关键在于理解C的内存管理模式.C里面有三种内存: ①.静态全局内存(生命周期从程序开始到程序结束,全局变量作用域是全局,静 ...

  9. POJ 3047 Bovine Birthday 日期定周求 泽勒公式

    标题来源:POJ 3047 Bovine Birthday 意甲冠军:.. . 思考:式 适合于1582年(中国明朝万历十年)10月15日之后的情形 公式 w = y + y/4 + c/4 - 2* ...

  10. 多个Storyboard切换

    - (void)showStoryboard { // 实例化MainStoryboard UIStoryboard *storyboard = [UIStoryboard storyboardWit ...