从这里开始是UI篇

知识点:

1.常用IOS基本控件

2.UITouch

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

常用基本控件

1.UISegmentedControl:分段控制器

1)创建方式

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

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

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

2)常用属性

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

  1. - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment
  2.  
  3. - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment
  4.  
  5. [seg setImage:[UIImage imageNamed:@"refresh_30"] forSegmentAtIndex:];

插入标题/图片

  1. - (void)insertSegmentWithTitle:(NSString *)title
  2.  
  3. atIndex:(NSUInteger)segment
  4.  
  5. animated:(BOOL)animated
  6.  
  7. - (void)insertSegmentWithImage:(UIImage *)image
  8.  
  9. atIndex:(NSUInteger)segment
  10.  
  11. animated:(BOOL)animated

//插入

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

  1. 移除内容
  2.  
  3. - (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated
  4.  
  5. - (void)removeAllSegments
  6.  
  7. //移除某一个分段
  8.  
  9. [seg removeSegmentAtIndex: animated:YES];
  10.  
  11. //移除所有分段
  12.  
  13. [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

  1. @property(nonatomic,retain) UIColor *minimumTrackTintColor
  2.  
  3. @property(nonatomic,retain) UIColor *maximumTrackTintColor
  4.  
  5. @property(nonatomic,retain) UIColor *thumbTintColor
  6.  
  7. //添加事件
  8.  
  9. [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
  10.  
  11. //设置左右颜色
  12.  
  13. slider.minimumTrackTintColor = [UIColor redColor];
  14.  
  15. slider.maximumTrackTintColor = [UIColor yellowColor];
  16.  
  17. 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

代理方法

  1. //实例化一个UIActionSheet
  2.  
  3. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"温馨提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"吃饭" otherButtonTitles:@"逛街",@"打游戏", @"睡觉",nil];
  4.  
  5. //显示UIActionSheet
  6.  
  7. [sheet showInView:self.view];
  8.  
  9. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  10.  
  11. //点击回调代理方法
  12.  
  13. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
  14.  
  15. NSLog(@"buttonIndex = %ld",buttonIndex);
  16.  
  17. switch (buttonIndex) {
  18.  
  19. case :
  20.  
  21. {
  22.  
  23. NSLog(@"吃饭");
  24.  
  25. }
  26.  
  27. break;
  28.  
  29. default:
  30.  
  31. break;
  32.  
  33. }
  34. }

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.如何捕捉触摸事件

  1. 触摸开始
  2.  
  3. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
  4.  
  5. 移动
  6.  
  7. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
  8.  
  9. 触摸结束
  10.  
  11. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
  12.  
  13. 触摸被取消(触摸时候程序被中断)
  14.  
  15. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
  16.  
  17. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  18.  
  19. //获得起始坐标
  20.  
  21. //取得触摸点对象
  22.  
  23. UITouch *touch = [touches anyObject];
  24.  
  25. //转换成坐标点
  26.  
  27. CGPoint point = [touch locationInView:self.view];
  28.  
  29. }

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. leetcode第31题--Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  2. 数据库备份还原工具EMS SQL Angel for SQL Server发布1.3版本

    EMS公司,是专门从事企业数据库以及内置于多层次客户服务器结构自动化开发.其EMS SQL Angel for SQL Server工具,便是SQL Servers数据库数据备份还原工具,并且还能使用 ...

  3. IE通过推理IE陈述的版本号

    样例: 1. <!--[if !IE]> 除IE外都可识别 <![endif]--> 2. <!--[if IE]> 全部的IE可识别 <![endif]-- ...

  4. 我的Android 4 学习系列之Intent 和 Broadcast Reciever

    目录 Intent 简介 使用隐式和显式Intent启动Activity.子Acitivity和Service 使用Linkify 使用Broadcast Intent 广播事件 使用 Pending ...

  5. apache kafkac系列lient发展-java

    apache kafka区QQ群:162272557 1.依赖包 <dependency>             <groupId>org.apache.kafka</ ...

  6. 【C#版本详情回顾】C#3.0主要功能列表

    隐式类型的本地变量和数组 在与本地变量一起使用时,var 关键字指示编译器根据初始化语句右侧的表达式推断变量或数组元素的类型 对象初始值设定项 支持无需显式调用构造函数即可进行对象初始化 集合初始值设 ...

  7. D15

    T3: 树上的递归,很裸 T4:题目模型:二分染色问题 以及根据ccy大神指点,理解树形dp可以从 没有上司的舞会 聚会的快乐 这两题入手

  8. oracle数据库对date字段类型存在空值进行排序的处理方法

    oracle数据库对date字段类型存在空值进行排序的处理方法      oracle 数据库,如果表中有一个字段类型为date,且该字段类型存在空值,并且需要排序,     解决方法为使用oracl ...

  9. 分布式搜索ElasticSearch构建集群与简单搜索实例应用

    分布式搜索ElasticSearch构建集群与简单搜索实例应用 关于ElasticSearch不介绍了,直接说应用. 分布式ElasticSearch集群构建的方法. 1.通过在程序中创建一个嵌入es ...

  10. Tomcat中Context的配置

    Tomcat直接ip地址访问不用加端口和项目名 当我们开发完一个WEB项目 然后部署到tomcat下,正常情况下应该是这样访问:http://localhost:端口号/项目名 如果我们想让用户仅仅输 ...