一、UITextField的代理方法

#pragma mark 当文本框开始编辑的时候调用---开始聚焦

- (void)textFieldDidBeginEditing:(UITextField *)textField

二、排序

1.可变数组的排序(NSMutableArray)

* sortUsingComparator:方法调完,会直接改变array这个可变数组内部对象的顺序

[array sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {

}];

* 排序过程中会不断地调用block,传入两个需要比较的对象:id obj1, id obj2

* block必须有返回值:NSComparisonResult

* NSComparisonResult有3种取值:

NSOrderedAscending = -1L, // 右边的对象排后面

NSOrderedSame, // 一样

NSOrderedDescending // 左边的对象排后面

2.不可变数组的排序(NSArray)

* sortedArrayUsingComparator:方法并不会改变array数组内部的顺序

* sortedArrayUsingComparator:方法会返回一个新的已经排好序的数组sortedArray

NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {

}];

三、监听键盘的显示和隐藏

1.监听键盘通知

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

// 1.显示键盘

[center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

// 2.隐藏键盘

[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

2.移除键盘通知(非ARC必须写)

- (void)dealloc

{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

3.注意点:当弹出一个新的键盘时,才会发出显示键盘的通知

四、UI控件常见属性总结

1.UIView

// 如果userInteractionEnabled=NO,不能跟用户交互

@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;

// 控件的标记(父控件通过标记可以找到对应的子控件)

@property(nonatomic) NSInteger tag;

// 控件的位置和尺寸(以父控件的左上角为坐标原点)

@property(nonatomic) CGRect            frame;

// 控件的位置和尺寸(以控件本身的左上角为坐标原点)

@property(nonatomic) CGRect            bounds;

// 控件的中点位置(以父控件的左上角为坐标原点)

@property(nonatomic) CGPoint           center;

// 形变属性:旋转、缩放、平移

@property(nonatomic) CGAffineTransform transform;

// 父控件

@property(nonatomic,readonly) UIView       *superview;

// 所有的子控件

@property(nonatomic,readonly,copy) NSArray *subviews;

2.UILabel

// 显示的文字

@property(nonatomic,copy)   NSString           *text;

// 字体

@property(nonatomic,retain) UIFont             *font;

// 文字颜色

@property(nonatomic,retain) UIColor            *textColor;

// 文字的排列方式(左对齐、居中、右对齐)

@property(nonatomic)        NSTextAlignment    textAlignment;

// 设置行数(行数==0代表自动换行)

@property(nonatomic) NSInteger numberOfLines;

3.UIImageView

// 显示的图片

@property(nonatomic,retain) UIImage *image;

// 设置序列帧图片数组(按顺序播放animationImages数组中的图片)

@property(nonatomic,copy) NSArray *animationImages;

// 序列帧动画的持续时间

@property(nonatomic) NSTimeInterval animationDuration;

// 序列帧动画的执行字数(默认是0,代表无限循环)

@property(nonatomic) NSInteger      animationRepeatCount;

4.UIScrollView

// 表示UIScrollView所滚动的位置

@property(nonatomic) CGPoint contentOffset;

// 表示UIScrollView的内容尺寸(能滚动的范围)

@property(nonatomic)         CGSize                       contentSize;

// 增加UIScrollView额外的边缘滚动区域

@property(nonatomic)         UIEdgeInsets                 contentInset;

// 代理

@property(nonatomic,assign) id<UIScrollViewDelegate>      delegate;

5.UITableView

6.UIPickerView

7.UIControl

// 是否可用

@property(nonatomic,getter=isEnabled) BOOL enabled;

// 自动拥有很多种状态

// 可以通过下面的方法来监听控件内部的一些事件:点击、值改变

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

1> UIDatePicker

// 设置模式(类型)

@property(nonatomic) UIDatePickerMode datePickerMode;

// 设置区域(zh_CN代表天朝)

@property(nonatomic,retain) NSLocale      *locale;

// 设置当前时间

@property(nonatomic,retain) NSDate        *date;

// UIDatePicker内部显示的日期更改了,就会触发值改变事件

2> UISwitch

// 控制开关状态

@property(nonatomic,getter=isOn) BOOL on;

- (void)setOn:(BOOL)on animated:(BOOL)animated;

// UISwitch内部开关状态更改了,就会触发值改变事件

3> UISegmentControl

// 一共有多少块区域

@property(nonatomic,readonly) NSUInteger numberOfSegments;

// 当前选中区域的位置

@property(nonatomic) NSInteger selectedSegmentIndex;

// UISegmentControl内部选中的区域更改了,就会触发值改变事件

4> UISlider

// 设置当前的进度值

@property(nonatomic) float value;

// 设置最小的进度值

@property(nonatomic) float minimumValue;

// 设置最大的进度值

@property(nonatomic) float maximumValue;

// UISlider内部的进度值更改了,就会触发值改变事件

5> UIButton

// 快速创建一个按钮

+ (id)buttonWithType:(UIButtonType)buttonType;

// 设置按钮的内边距

@property(nonatomic) UIEdgeInsets contentEdgeInsets;

// 按钮内部的标签控件

@property(nonatomic,readonly,retain) UILabel     *titleLabel;

// 按钮内部的图片控件

@property(nonatomic,readonly,retain) UIImageView *imageView;

// 设置内部titleLabel显示的文字

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

// 设置内部titleLabel的文字颜色

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

// 设置内部imageView显示的图片

- (void)setImage:(UIImage *)image forState:(UIControlState)state;

// 设置背景图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

- (NSString *)titleForState:(UIControlState)state;

- (UIColor *)titleColorForState:(UIControlState)state;

- (UIImage *)imageForState:(UIControlState)state;

- (UIImage *)backgroundImageForState:(UIControlState)state;

6> UITextField(通过delegate监听内部的事件)

8.UIAlertView

// 创建一个UIAlertView对话框

/*

title : 对话框标题

message : 对话框中间显示的文字内容

cancelButtonTitle : 取消按钮的文字

otherButtonTitles : 其他按钮的文字(设置多个)

delegate : 用来监听alertView上面按钮的点击

*/

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

// 显示

- (void)show;

五、项目常见文件

1.main.m

* 里面有一个程序的入口:main函数

2.Prefix.pch文件

* pch文件中的内容能被项目中的其他任何文件共享\包含\访问

* 如果定义的内容只用在OC环境中,就必须定义在#ifdef __OBJC__和#endif之间

3.发布程序的时候自动去除打印语句

#ifdef DEBUG

#define MyLog(...)  NSLog(__VA_ARGS__)

#else

#define MyLog(...)

#endif

4.InfoPlist.strings

* 跟app的本地化相关(多语言版本)

5.Info.plist

1> 全局配置文件

2> 新旧配置文件的对比

Xcode3的时候,全局配置文件名:Info.plist

Xcode4开始,全局配置文件名:项目名-Info.plist

3> 项目中自定义的plist文件中不要包含info这个字眼

4> 常见的配置

Bundle display name : 软件名称

Bundle identifier : app的唯一标识

Bundle versions string, short : 软件版本号(更新app)

Main storyboard file base name : 设置程序一启动就加载的storyboard文件

六、屏幕适配

1.为非视网膜\视网膜屏幕分别准备2份图片,比如:

1> 非视网膜 abc.png

2> 视网膜 abc@2x.png

2.程序启动图片

* 程序启动过程中会自动全屏显示Default.png图片,程序启动完毕就会隐藏Default.png图片

* Default.png 非视网膜

* Default@2x.png 3.5英寸的视网膜

* Default-568h@2x.png 4英寸的视网膜

3.软件图标

* 系统会自动把Icon.png当做应用程序的软件图标

* 关于软件的图标规格,可以搜索官方文档:app icon

七、UIApplication

1.简介

1> 整个应用程序的象征,一个应用程序就一个UIApplication对象,使用了单例设计模式

2> 通过[UIApplication sharedApplication]访问这个单例对象

2.常见用法

1> 设置图标右上角的红色提示数字

app.applicationIconBadgeNumber = 10;

2> 设置状态栏的样式

app.statusBarStyle = UIStatusBarStyleBlackOpaque;

3> 控制状态栏的显示和隐藏

app.statusBarHidden = YES;

4> 显示状态栏上面的圈圈

app.networkActivityIndicatorVisible = YES;

5> 打开外部资源

* 打开网页

[app openURL:[NSURL URLWithString:@"http://www.baidu.com"]];

* 打电话

[app openURL:[NSURL URLWithString:@"tel://10086"]];

* 发短信

[app openURL:[NSURL URLWithString:@"sms://10086"]];

6> 代理属性(当应用程序发生了一些系统级别的事件,就会通知代理,交给代理去处理)

@property(nonatomic,assign) id<UIApplicationDelegate> delegate;

八、UIApplicationDelegate的代理方法

#pragma mark  程序加载完毕(启动完毕)就会调用一次

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

#pragma mark 应用程序失去焦点的时候调用(一个app如果失去焦点,就不能跟用户进行交互)

- (void)applicationWillResignActive:(UIApplication *)application

#pragma mark 程序进入后台就会调用

- (void)applicationDidEnterBackground:(UIApplication *)application

#pragma mark 程序即将进入前台的时候调用

- (void)applicationWillEnterForeground:(UIApplication *)application

#pragma mark 应用程序获得焦点的时候调用(一个app只有获得焦点之后才能跟用户进行交互)

- (void)applicationDidBecomeActive:(UIApplication *)application

#pragma mark 程序即将被关闭的时候可能会被调用

- (void)applicationWillTerminate:(UIApplication *)application

#pragma mark 程序接收到内存警告都会调用

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application

IOS数组排序等的更多相关文章

  1. iOS数组排序 请求后,数组元素的排序 时间戳,最热,点赞数等

    [ZOYSessionManager dataWithUrlString:GetVideoDataComment andParameter:@{@"id":userID,@&quo ...

  2. ios 数组排序

    第一种:利用数组的sortedArrayUsingComparator调用 NSComparator  示例: obj1和obj2指的是数组中的对象 //1.数组中存放的是字符 NSComparato ...

  3. iOS数组排序

    [_fields sortUsingComparator:^NSComparisonResult(UITextField *obj1, UITextField *obj2) { /* NSOrdere ...

  4. iOS数组使用

    相关链接: ios数组基本用法和排序 NSArray 排序汇总 iOS 数组排序方法 IOS-筛选数组内的元素 关于EnumerateObjectsUsingBlock和for-in之间的较量 [iO ...

  5. IOS对存放对象的数组排序

    我们开发的每个程序都会使用到一些数据,而这些数据一般被封装在一个自定义的类中.例如一个音乐程序可能会有一个Song类,聊天程序则又一个 Friend类,点菜程序会有一个Recipe类等.有时候我们希望 ...

  6. iOS学习16之OC集合遍历和数组排序

    1.集合遍历 1> 遍历 集合(Collection):OC中提供的容器类:数组,字典,集合. 遍历:对集合中元素依次取出的过称叫做遍历. 三种方式:① for循环遍历: ② NSEnumera ...

  7. iOS学习之Object-C语言集合遍历和数组排序

    一.集合遍历      1.集合:OC中提供的容器类,数组,字典,集合.      2.遍历:对集合中元素依次取出的过程叫做遍历. 二.for循环遍历      1.通过for循环的循环变量用作数组元 ...

  8. iOS之NSArray数组排序

    一.数组遍历 除了常用的for和for-in遍历外,系统还提供了三种枚举遍历,对于大量的数据遍历可以使用下列三个方法. - (void)enumerateObjectsUsingBlock:(void ...

  9. iOS 二维数组排序小算法

    NSArray *tmp = @[@[@(1), @(2), @(3), @(4), @(5)],                     @[@(6), @(7), @(8), @(9), @(10 ...

随机推荐

  1. Unity 二战中加飞机

    一个简短的引论: 谢意: 本申请中使用<Unity3D\2D移动游戏开发>提供资源.著作权属于作者.感谢作者.基于原始时本申请的二次开发. 要素: 1.增加2s cd的机身旋转,旋转时保持 ...

  2. phpword这个问题的产生中国扭曲

    采用phpword经word模板生成word当文件,乱码的问题.矿php和所有的数据库使用urf8编码格公式.解决的办法是,到场/phpword/template.php档,守则   $replace ...

  3. Windows在生产体系Android开关机动画

    在Windows根据系统.办Android开关机动画,几个需要注意的问题: 1.压缩的选择 2.压缩的格式: 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  4. IOS应用上传须要做的工作

    苹果开发人员   https://developer.apple.com/ 证书创建流程 certificates (证书): 是电脑可以增加开发人员计划的凭证 证书分为:开发证书和公布(产品)证书, ...

  5. HDU 3832 Earth Hour(最短路)

    题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...

  6. jquery.validate.unobtrusive

    ASP.NET MVC Unobtrusive JavaScript 实现 onfocusout 验证, onfocusin 清除错误 在 ASP.NET MVC 中启用 Unobtrusive Ja ...

  7. js 网上见到的动画函数 备份

    <script> function startMove(obj,json,fn){ clearInterval(obj.timer); obj.timer = setInterval(fu ...

  8. 应用spss可靠性分析软件

    问卷调查的可靠性分析 一.概念:     信度是指依据測验工具所得到的结果的一致性或稳定性,反映被測特征真实程度的指标. 一般而言,两次或两个測验的结果愈是一致.则误差愈小,所得的信度愈高,它具有下面 ...

  9. PHP操作XML文件学习笔记

    原文:PHP操作XML文件学习笔记 XML文件属于标签语言,可以通过自定义标签存储数据,其主要作用也是作为存储数据. 对于XML的操作包括遍历,生成,修改,删除等其他类似的操作.PHP对于XML的操作 ...

  10. (大数据工程师学习路径)第一步 Linux 基础入门----数据流重定向

    介绍 开始对重定向这个概念感到些许陌生,但通过前面的课程中多次见过>或>>操作了,并知道他们分别是将标准输出导向一个文件或追加到一个文件中.这其实就是重定向,将原本输出到标准输出的数 ...