从这里开始是UI篇

知识点:

1.常用IOS基本控件

2.UITouch

=======================

常用基本控件

1.UISegmentedControl:分段控制器

1)创建方式

- (id)initWithItems:(NSArray *)items;

items数组中可以有NSString或者是UIImage对象

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"广州",@"深圳",@"珠海"]];

2)常用属性

设置标题/图片(注意下标范围从0~segments-1)

- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment

- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment

[seg setImage:[UIImage imageNamed:@"refresh_30"] forSegmentAtIndex:];

插入标题/图片

- (void)insertSegmentWithTitle:(NSString *)title 

              atIndex:(NSUInteger)segment 

      animated:(BOOL)animated

- (void)insertSegmentWithImage:(UIImage *)image  

      atIndex:(NSUInteger)segment 

      animated:(BOOL)animated

//插入

[seg insertSegmentWithTitle:@"湛江" atIndex:3 animated:YES];

移除内容

- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated

- (void)removeAllSegments

//移除某一个分段

[seg removeSegmentAtIndex: animated:YES];

//移除所有分段

[seg removeAllSegments];

事件处理

- (void)addTarget:(id)target

action:(SEL)action

forControlEvents:(UIControlEvents)controlEvents

3)事件处理

UIControlEventValueChanged

//添加事件

//注意事件类型使用:UIControlEventValueChanged

[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

2.UISlider:滑块

1)创建方式

2)常用属性

当前value

property(nonatomic) float value

//实例化一个UISlider

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 80, 200, 100)];

//设置默认滑块的位置(默认是0 - 1范围)

slider.value = 0.5;

最小value

@property(nonatomic) float minimumValue

最大value

@property(nonatomic) float maximumValue

//修改最大最小值

slider.minimumValue = 10;

slider.maximumValue = 100;

3)定制UI

@property(nonatomic,retain) UIColor *minimumTrackTintColor

@property(nonatomic,retain) UIColor *maximumTrackTintColor

@property(nonatomic,retain) UIColor *thumbTintColor 

    //添加事件

[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

    //设置左右颜色

slider.minimumTrackTintColor = [UIColor redColor];

slider.maximumTrackTintColor = [UIColor yellowColor];

slider.thumbTintColor = [UIColor purpleColor];

3.UISwitch:开关控件

1)创建方式

// 实例化一个UISwitch

UISwitch *swi = [[UISwitch alloc] initWithFrame:CGRectMake(30, 80, 10, 10)];

2)常用属性

@property(nonatomic, retain) UIColor *onTintColor

@property(nonatomic, retain) UIColor *thumbTintColor

@property(nonatomic,getter=isOn) BOOL on

//设置按键颜色

swi.thumbTintColor = [UIColor orangeColor];

//打开的颜色

swi.onTintColor = [UIColor purpleColor];

//设置开关状态

swi.on = NO;

3)事件处理

[swi addTarget:self action:@selector(swiAction:) forControlEvents:UIControlEventValueChanged];

4.UIActivityIndicatorView

1)创建方式

- (id)initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style

   UIActivityIndicatorViewStyleWhiteLarge     大白色

UIActivityIndicatorViewStyleWhite            普通大小白

  UIActivityIndicatorViewStyleGray              普通大小灰

// 加载视图

UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30, 100, 200, 200)];

act.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

2)常用属性

开始转动

- (void)startAnimating;

停止转动

- (void)stopAnimating;

是否正在转动

- (BOOL)isAnimating;

颜色

@property (readwrite, nonatomic, retain) UIColor *color

//设置颜色

act.color = [UIColor orangeColor];

//开启动画

[act startAnimating];

//停止动画

[act stopAnimating];

//设置停止动画依然显示

act.hidesWhenStopped = NO;

5.UIProgressView:进度条

1)创建方式

- (id)initWithProgressViewStyle:(UIProgressViewStyle)style

UIProgressView *pro = [[UIProgressView alloc] initWithFrame:CGRectMake(30, 100, 200, 30)];

2)常用属性

@property(nonatomic) float progress   当前进度

@property(nonatomic, retain) UIColor* trackTintColor

@property(nonatomic, retain) UIColor* progressTintColor

//默认的范围为0 - 1

//设置进度

pro.progress = 0.5;

//完成进度的颜色

pro.progressTintColor = [UIColor redColor];

//未完成进度的颜色

pro.trackTintColor = [UIColor greenColor];

练习:模仿进度读取状态

6.UIActionSheet

代理方法

//实例化一个UIActionSheet

    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"温馨提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"吃饭" otherButtonTitles:@"逛街",@"打游戏", @"睡觉",nil];

    //显示UIActionSheet

    [sheet showInView:self.view];

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

//点击回调代理方法

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSLog(@"buttonIndex = %ld",buttonIndex);

    switch (buttonIndex) {

        case :

        {

            NSLog(@"吃饭");

        }

            break;        

        default:

            break;

    }
}

7.UIAlertView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

//实例化一个UIAlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"余额不足" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"抢银行",@"搬砖",@"找个富婆", nil];

//展示

[alert show];

}

#pragma mark- UIAlertViewDelegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

NSLog(@"buttonIndex = %ld",buttonIndex);

}

=======================

UITouch

1.如何捕捉触摸事件

触摸开始

      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

      移动

      - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

      触摸结束

      - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

      触摸被取消(触摸时候程序被中断)

      - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    //获得起始坐标

    //取得触摸点对象

    UITouch *touch = [touches anyObject];

    //转换成坐标点

    CGPoint point = [touch locationInView:self.view];

}

2.如何获取坐标信息

1)获取到触摸点

UITouch *touch=[touches anyObject]

//获得起始坐标

//取得触摸点对象

UITouch *touch = [touches anyObject];

2)转换为坐标点

[touch locationInView:self.view]

CGPoint point = [touch locationInView:self.view];

iOS开发-UI (一)常用控件的更多相关文章

  1. iOS开发UI篇—UIScrollView控件介绍

    iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...

  2. iOS开发UI篇—UITableview控件简单介绍

    iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...

  3. iOS开发UI篇—UIScrollView控件实现图片缩放功能

    iOS开发UI篇—UIScrollView控件实现图片缩放功能 一.缩放 1.简单说明: 有些时候,我们可能要对某些内容进行手势缩放,如下图所示 UIScrollView不仅能滚动显示大量内容,还能对 ...

  4. iOS开发UI篇—UITableview控件基本使用

    iOS开发UI篇—UITableview控件基本使用 一.一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) #import <Foundation/Foundation.h> ...

  5. iOS开发UI篇—UITableview控件使用小结

    iOS开发UI篇—UITableview控件使用小结 一.UITableview的使用步骤 UITableview的使用就只有简单的三个步骤: 1.告诉一共有多少组数据 方法:- (NSInteger ...

  6. iOS开发UI篇—UIScrollView控件实现图片轮播

    iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播            二.实现代码 storyboard中布局 代码: #import "YYV ...

  7. 【转】 iOS开发UI篇—UIScrollView控件实现图片轮播

    原文:http://www.cnblogs.com/wendingding/p/3763527.html iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播 ...

  8. iOS开发之七:常用控件--UISlider、UISegmentedControl、UIPageControl的使用

    一.UISlider的使用 其实UISlider在iOS开发中用的似乎不是很多,我们看到的用到的地方多是音乐播放器的音量控制,以及视频播放器中的音量控制. 还是记录一下吧! 1.常用属性 // 设置获 ...

  9. iOS开发之六:常用控件--UIImageView的使用

    UIImageView是我们做iOS开发用的非常多的一个控件,IOS中的各种图片,包括头像,有的背景图片等基本都要用到这个控件. 1.常用的属性以及方法 <span style="fo ...

随机推荐

  1. DDD分层架构之我见

    DDD分层架构之我见 前面介绍了应用程序框架的一个重要组成部分——公共操作类,并提供了一个数据类型转换公共操作类作为示例进行演示.下面准备介绍应用程序框架的另一个重要组成部分,即体系架构支持.你不一定 ...

  2. easyui datagrid显示进度条控制操作

    在当我们需要控制时间前台实际项目页面datagrid显示进度条的数据加载时运行,和datagrid默认情况下只在有url加载运行时的数据显示方式的进度条.下面的代码手动控制: 打开一个进度条: $(' ...

  3. 【工作笔记三】非常全面的讲解Hosts文件

    原文:http://www.cnblogs.com/zgx/archive/2009/03/10/1408017.html 很奇怪有很多人不知道Hosts是什么东西.在网络病毒日渐盛行的今天,认识Ho ...

  4. 【转】android 欢迎界面翻页成效,仿微信第一次登陆介绍翻页界面

    android 欢迎界面翻页效果,仿微信第一次登陆介绍翻页界面 本实例做的相对比较简单主要是对翻页控件的使用,有时候想要做一些功能是主要是先了解下是否有现成的控件可以使用,做起来比较简单不用费太大的劲 ...

  5. centos 4.4配置使用 and Nutch搜索引擎(第1期)_ Nutch简介及安装

    centos 4.4配置使用 1.Nutch简介 Nutch是一个由Java实现的,开放源代码(open-source)的web搜索引擎.主要用于收集网页数据,然后对其进行分析,建立索引,以提供相应的 ...

  6. 一个Shift的后门程序,可以让你可以进入你不知道密码的电脑

    1.前提 你可以在平时亲身接触状态电脑,哪怕是在电脑主人不在的时候(虽然主人不在,或者关机了,进入电脑是要密码的). 2.原理 利用电脑连续按5次Shift会触发粘滞键,它会运行c:\winows\s ...

  7. MINIGUI 编译 helloworld

    MiniGui 编译hello.c 文件成功!记载一下! MiniGui 版本v3.0 和 2 编译 差异 是极其的大!   源文件代码 :   #include <stdio.h>#in ...

  8. c# UDP/TCP协议简单实现(简单聊天工具)

    长时间没有摸这两个协议,写个代码温习下 下面是界面 [服务器界面] [登陆界面] [好友列表界面(我登陆了2个)] [聊天界面] 下面大致讲解下用到的内容 1.用户登陆于服务器通信用到的tcp协议,服 ...

  9. 关于grub的那些事(三)

    接着第二篇的研究,继续分析/etc/grub.d/10_linux. #! /bin/sh set -e prefix="/usr" exec_prefix="${pre ...

  10. js 获取某年的某天是第几周

    /** * 判断年份是否为润年 * * @param {Number} year */ function isLeapYear(year) { return (year % 400 == 0) || ...