iOS基础UI


http://wquanfeng.blog.51cto.com/6316183/1228118

UI方面的一些内容:


1.UILabel
 iPhone平台提供了两种绘图库: Quartz 2D 和 OpenGL ES, 其中Quartz 2D是Core Graphics绘图库的子集, OpenGL ES是跨平台图形库OpenGl的嵌入设备版 (Embedded System); Quartz的原点在左上角, OpenGL ES的原点在左下角.
 1) label.frame         //CGRectMake(x, y, width, height);
 2) label.text            //label.textColor
 3) label.backgroundColor        //UIColor  redColor  colorWithRed: green: blue: alpha:
 4) label.textAlignment    //UITextAlignmentCenter Left Right
 5) label.font            //UIFont familyNames  boldSystemFontOfSize:    [UIFont fontWithName: size: ]
 6) label.shadowOffset        //CGSizeMake(width, height)
 7) label.shadowColor
 8) label.lineBreakMode    //UILineBreakModeWordWrap
 9) label.numberOfLines
10) CGSize size = [string sizeWithFont: constrainedToSize: lineBreakMode:];
11) [self.window addSubview: ];
12) label.adjustsFontSizeToFitWidth = YES;

2.UIButton
 继承自UIControl, UIControl是在UIView的基础上增加了一个点击事件
 1) buttonWithType:  
   //初始化只有这一种方法, UIButtonTypeRoundedRect, InfoLight, InfoDark, ContactAdd, DetailDisclosure, Custom
 2) setTitle: forState:    //UIControlStateNormal, Highlighted
 3) setTitleColor: forState:
 4) setTintColor:        //按钮点击后的颜色, 只有RoundedRect有这个效果
 5) button.tag            //设置标识属性, 唯一标识一个view
 6) addTarget:self action:@selector() forControlEvents:    //在哪个事件下, 执行哪个对象的方法, UIControlEventTouchUpInside
               //哪个对象调用这个@selector(buttonClick:), 这个对象就作为参数传给buttonClick:
 7) setBackgroundImage: forState:    
 8) setImage: forState:

3.UIView
 所有能看的见的都是view
 CGRect frame = {CGOrigin, CGSize};    CGOrigin = {x, y}; //坐标是相对的    CGSize = {width, height};
 CGPoint center = {x, y};
 CGRect bounds;
 CGRectContainsPoint(rect, point);    // 判断点point是否在rect内
 [self.window sendSubviewToBack: ];    bringSubviewToFront:    exchangeSubviewAtIndex: withSubviewAtIndex:
 insertSubview: atIndex:     insertSubview: belowSubview:    insertSubview: aboveSubview:
 view.tag    [self.view viewWithTag: ]    // 根据tag值, 得到对应的view
 view.clipsToBounds = YSE;    // 自动剪裁掉超出本身frame大小的子view的内容
 view.contentMode        // 内容填充模式
 view.autoresizesSubviews = YSE;    // 设置当前view的子view可以自动布局
 subview.autoresizingMask = UIViewAutoresizingFlexibleWidth;    // 增加多个自动布局模式, 可以使用位或运算 (|)
 [UIView animateWithDuration: animations:^{  } completion:^(BOOL finished){  }];    // UIView动画

 [UIScreen mainScreen]        // 获得屏幕类对象
   currenMode
 [UIDevice currentDevice]    // 获得当前设备类对象
   name, systemName, SystemVersion

4.UIImageView
 [UIImage imageNamed:]
 image.size.width    image.size.height
 initWithImage:
 imageView.image        // imageView中的image
 NSData *data = UIImagePNGRepresentation(imageView.image);    // 将PNG图片转成二进制数据
 UIImageJPEGRepresentation(imageView.image, 0.5)    // 转换JPEG图片, 第二个参数为压缩比0到1之间的数
 UITapGestureRecognizer    // 点击手势
   initWithTarget: self action: @selector()
     numberOfTapsRequired    // 点击次数 (默认为1)
   numberOfTouchesRequired    // 几只手指点击 (默认为1)
   tapGestureRecognizer.view.tag    // 被点击的view的tag
   gesture.view        // 得到点击的视图
   [gesture state]        // 手势的状态, UIGestureRecognizerStateBegan等
   [gesture locationInView: ]    // 点击手势在视图中的位置
 addGestureRecognizer:        // 加入手势
 imageView.userInteractionEnabled = YES  // 打开imageView的交互功能
 ImageView动画, 将一组图片放到一个数组中
 imageView.animationImages = imagesArray;
 imageView.animationDuration = 1;    // 动画周期时间
 imageView.animationRepeatCount = 5;    // 默认是无限次
 startAnimating    stopAnimating

5.UIViewController
 分为view和controller两部分, 能看到的只有view
 self.view.backgroundColor
 self.window.rootViewController = rootViewController;    // 在window中添加主视图控制器
 presentViewController: animated: YES completion:^{ }    // 窗体跳转
 subViewController.modalTransitionStyle = UIModalTransitionsStyleFlipHorizontal;    // 跳转风格
 dismissViewControllerAnimated: YES completion:^{ }    // 关闭对话窗口, 即返回上一个窗口

 函数介绍:
   1)-(id)initWithNibName: bundle:     // 将xib文件转换为nib描述文件
   2)-(void)loadView            // 用于初始化nib文件里描述的控件
   3)-(void)viewDidLoad            // 进一步修改self.view(即修改手写控件), 默认只执行一次, 只有当系统内存不够时, 才会自动调用viewDidUnLoad方法再次执行
   4)-(void)viewWillAppear:        // 当界面当要进入时显示 (界面不可见)
   5)-(void)viewDidAppear:            // 当界面已经显示时调用 (界面可见)
   6)-(void)viewWillDisappear:        // 当界面将要退出时调用 (界面可见)
   7)-(void)viewDidDisappear:        // 当界面已经退出后调用 (界面不可见)
   8)-(void)didReceiveMemoryWarning    // 当内存不够用时, 系统自动调用此方法, 释放自己写入的内容的内存, 不会销毁
   9)-(void)viewDidUnload            // 当内存不够用时, 系统自动调用此方法, 直接销毁界面

6.UINavigationController
 window -> UINavigationController -> UIViewController -> view
 initWithRootViewController: rootViewController;
 self.window.rootViewController = navigationController;
 [self.navigationController pushViewController: animated: YES]    // 压入当前视图控制器, 即进入这个页面
 [self.navigationController popViewControllerAnimated: YES]    // 弹出当前视图控制器, 即返回上个页面
 [self.navigationController popToRootViewControllerAnimated: YES];    // 弹出导航控制器中所有视图控制器到主视图控制器
 self.navigationController.viewControllers    // 得到导航控制器中所有的视图控制器对象数组, 所有的视图控制器共用一个导航控制器
 [self.navigationController popToViewController: animated: YES]    // 弹出一些视图控制器, 到指定视图控制器上

7.UINavigationBar
 self.navigationController.navigationBar.barStyle = UIBarStyleBlack;    // 设置导航条, 如果用半透明模式view.frame就是正常的
 self.navigationController.navigationBar.backgroundColor    // 只有半透明模式才能设置颜色, 而且还会和黑色半透明的相融合
 self.navigationController.navigationBar.frame        // 设置导航条frame, 默认高度为44
 self.navigationController.navigationBar setBackgroundImage: forBarMetrics: UIBarMetricsDefault
     // 设置导航条背景图片, BarMetrics是iPhone形式(人像, 景色), 图片不会拉伸压缩, 如果图片过大, 会覆盖到下面的视图控制器
 self.navigationController.navigationBar.hidden = YES;    // 隐藏导航条
 [self.navigationController setNavigationBarHidden: YES animated: YES]

8.UINavigationItem
 每一个界面都有自己对导航控制器的描述
 self.navigationItem.title        // 设置标题, 居中显示
 self.navigationItem.titleView        // 设置标题视图, view中的frame的x, y不会影响titleView的位置, 永远居中显示
 UIBarButtonItem            // 专门用于设置导航条按钮和工具条按钮
   initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target: self action: @selector() // 使用系统提供按钮
   initWithTitle: style: UIBarButtonItemsStylePlain target: self action: @selector()    // 自定义标题
       // Plain风格会根据导航条风格变换颜色, Done风格永远为蓝色
   initWithCustomView:    // 自定义view
 self.navigationItem.leftBarButtonItem = barButtonItem;    rightBarButtonItem
 self.navigationItem.rightBarButtonItems = barButtonItemsArray    // 在导航控制器一侧加入多个按钮, 先将按钮放入数组中

9.UIToolbar
 只要有导航控制器就有工具条, 没有导航控制器就没有工具条, 一般工具条是隐藏的.
 [self.navigationController setToolbarHidden: NO animated: YES];    // 显示工具条
 UIBarButtonSystemItemFlexibleSpace是加空格用的
 self.toolbarItems = barButtonItemsArray    // 将按钮加到工具条上
 [self.navigationController.toolbar setBackgroundImage: forToolbarPosition: UIToolbarPositionBottom barMetrics: UIBarMetricsDefault];        // forToolbarPosition当工具条在哪个位置的时候显示图片
 self.navigationController.toolbar.frame    // 设置工具条位置

10.UITextField
 文本输入框, 背景默认为透明色, clearColor, 使用代理收起键盘<UITextFieldDelegate>
 textField.text    // 文本框中的内容
 textField.borderStyle = UITextBorderStyleRoundedRect;        // 设置边框样式
 textField.placeholder        // 设置提示文字
 textField.keyboardType = UIKeyboardTypeEmailAddress;        // 设置键盘样式
 textField.secureTextEntry = YES;    // 设置密文输入
 textField.clearButtonMode = UITextFieldViewModeWhileEditing;    // 设置清空按钮
 [textField resignFirstResponder];    // 取消第一响应者, 让文本输入框收起键盘退出编辑模式
 [textField becomeFirstResponder];    // 让文本输入框成为第一响应者, 弹出键盘进入编辑模式

11.UITextView
 textView.text        // 设置UITextView中的文字
 textView.font        // 设置UITextView的字体
 textView.editable = NO    // 设置textView不能编辑

12.[NSNotificationCenter defaultCenter]
 系统通知中心, 是观察者模式的一种体现 (在IOS中: 代理用作1对1, 通知中心用作多对多); 通知中心只有三种操作, 订阅消息, 发送消息, 取消订阅消息
 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillShow) name: UIKeyboardWillShowNotification object: nil]    // 键盘将要升起时, 发送一条消息给@selector(), 还有WillHide

13.UISegmentedControl
 将一组选项放在数组中, initWithItems: array
 [segmentedControl insertSegmentWithTitle: atIndex: animated: ];
 segmentedControl.selectedSegmentIndex        // 选中的选项的索引
 [segmentedControl titleForSegmentAtIndex: ]    // 指定索引文字的选项
 segmentedControl.momentary = YES    // 默认选项选中后会一直保持选中状态, 设为YES会变为原样
 UISegmentedControlStyle        // 设置控件风格, 默认为Plain
 [segmentedControl setTintColor: ]    // 设置色调
 [segmentedControl addTarget: self action: @selector() forControlEvents: UIControlEventValueChanged];

14.UISwitch
 frame的宽和高, 对开关没影响
 [switch setOn: YES animated: YES]        // 设置开关为开状态, 默认是关
 [switch addTarget: self action: @selector() forControlEvents: UIControlEventValueChanged];
 switch.isOn        switch.isOff

15.UISlider
 slider.minimumValue        // 设置最小值
 slider.maximumValue        // 设置最大值
 slider.value            // 设置当前默认值
 setThumbImage: forState:    // 设置slider上的小滑块thumb的图片
 [slider addTarget: self action: @selector() forControlEvents: UIControlEventValueChanged];     // 增加滑动事件

16.UIProgressView
 initWithProgressViewStyle: UIProgressViewStyleDefault
 progressView.progress        // 设置进度条的值

17.UIStepper
 stepper.maximumValue        // 设置最大值, 默认为0 - 100
 stepper.minimumValue        // 设置最小值
 stepper.stepValue        // 设置步长
 addTarget: self action: @selector() forControlEvents:    UIControlEventValueChanged    // 添加点击事件

18.UIActivityIndicatorView (活动等待器)
 initWithActivityIndicatorStyle: UIActivityIndicatorStyleWhite    // 设置模式
 [activityIndicatorView startAnimating];        // 开始
 [activityIndicatorView stopAnimating];        // 停止

19.UITouch
 touch有三个函数, 点击时, 会自动调用这三个函数, 不需要初始化, 直接用这三个函数就行, touch得到的是坐标
 -(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
 {
   // 在哪个view中就相对于哪个view计算坐标
   CGPoint point = [[touches anyObject] locationInView: ];
 }
 -(void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event
 -(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event

20.UIGestureRecognizer(抽象类, 手势)
 1)UITapGestureRecognizer        // 点击
 2)UIPinchGestureRecognizer        // 捏合
   gestureRecognizer.scale            // 比例
 3)UIRotationGestureRecognizer        // 旋转
   [gestureRecognizer rotation]        // 弧度
 4)UISwipeGestureRecognizer        // 滑动, 快速滑动, 用于监测滑动的方向
   [swipe setDirection:UISwipeGestureRecognizerDirectionUp]    // 向上
 5)UIPanGestureRecognizer        // 托移, 慢速移动, 用于监测偏移的量
 6)UILongPressGestureRecognizer    // 长按
 [A requireGestureRecognizerToFail: B]    // A手势满足条件, 不会立即触发, 等B手势确定失败后再触发A手势

21.UIWebView
 NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: ]];    // 新建一个request
 [webView loadRequest: request];    // 装载request
 webView.scalesPageToFit = YES;    // 自动适应到当前屏幕大小
 [webView loadHTMLString: baseURL: nil]    // 装载本地HTML String
 <UIWebViewDelegate>    // webView的各种状态都是通过delegate回调获得的
   - (BOOL)webView: shouldStartLoadWithRequest: navigationType:
   - (void)webViewDidStartLoad:(UIWebView *)webView;
   - (void)webViewDidFinishLoad:(UIWebView *)webView;
   - (void)webView:(UIWebView *)webView didFailLoadWithError: (NSError *)error;

22.UITabBarController
 高度为49, 视图控制器的height会从原来的460缩小到411, 每个选项卡都是相对独立的, 互不影响
 viewController.title        // 设置TabBarController上的标题
 viewController.tabBarItem.image        // 设置TabBarController上的图片
 viewController.tabBarItem.badgeValue    // 设置选项卡微标
 UITabBarItem * tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem: tag: ]    // 使用系统自带样式选项卡, 为了能得到选项卡标题, 还应该手动设置下title.
 tabBarController.viewControllers = array;    // 数组中存储各种视图控制器或导航控制器
 tabBarController.selectedIndex        // 设置默认选中的选项卡
 tabBarController.selectedViewController
 一个TabBarController中包含两个子view (第一个子view用来显示状态栏, 导航控制器, 视图控制器等; 第二个子view为选项卡)
 隐藏TabBarController时需要将第二个的子view的坐标移到屏幕外, 并将第一个view的高度改为480  
 tabBarController.view.subviews    // 选项卡控制器中的两个子视图
 tabBarController.viewControllers    // 选项卡控制器中的所有控制器

 tabBarController.delegate = self;        // 设置代理<UITabBarControllerDelegate>
 -(void) tabBarController: didSelectViewController:    // 点中选项卡后会触发此代理中的方法
 -(void) tabBarController: didEndCustomizingViewControllers: changed:     // 编辑结束后触发此方法

23.NSUserDefaults
 NSUserDefaults是一中本地存储机制, 保存的内容不会消失(下次打开看程序时还会出现), 用来存储一些如对程序的设置等小型数据,
 能存储的数据类型: NSString, NSNumber, NSArray, NSDictionary, NSData, NSDate,
 用法类似于字典, 整个程序中有且只有一个UserDefaults.
 [NSUserDefaults standardUserDefaults]        // 声明, 只能用这一种方法
 [userDefaults setObject: forKey: ]        // 存储数据
 [userDefaults synchronize]            // 同步给系统, 否则不能保存
 [userDefaults objectForKey: ]            // 读取数据
 [userDefaults removeObjectForKey: ]        // 清楚保存的值

24.UIScrollView
 scrollView.contentSize    // 只有当contentSize大于frame时才可以滚动
 scrollView.showsHorizontalScrollIndicator = NO;    // 隐藏横向滚动条
 scrollView.showsVerticalScrollIndicator = NO;        // 隐藏纵向滚动条
 scrollView.bounces = NO;    // 取消弹性机制
 scrollView.scrollEnabled = YES;    // scrollView是否可以滚动
 scrollView.pagingEnabled = YES;    // 设置按页翻滚, 一页的大小就是frame的大小
 scrollView.contentOffset = point;    // 设置偏移量
 [scrollView setContentOffset: animated: ]
 scrollView.delegate = self;        // <UIScrollViewDelegate>
 协议中的函数:
   -(void) scrollViewWillBeginDragging:            // 开始拖拽的时候调用此函数
   -(void) scrollViewDidScroll:                // 滚动中调用此函数
   -(void) scrollViewDidEndDragging: willDecelerate:    // 结束拖拽的时候调用此函数
   -(void) scrollViewWillBeginDecelerating:        // 开始减速的时候调用此函数
   -(void) scrollViewDidEndDecelerating:            // 结束减速的时候调用此函数
 设置scrollView缩放
   1)加上scrollView的delegate
   2)设置最大放大倍数和最小缩小倍数
     scrollView.maximumZoomScale = 3.0;    scrollView.minimumZoomScale = 1.0;
   3)实现协议中的放大缩小方法
     -(UIView *) viewForZoomingInScrollView:
       return [scrollView.subviews objectAtIndex: ];    // 放大缩小哪个view就返回哪个view
   4)不用去考虑contentSize的变化, 系统会自动完成

25.UITableView
 UITableView使用的都是协议中的方法, <UITableViewDataSource, UITableViewDelegate>
 tableView.dataSource = self;    tableView.delegate = self;
 [tableView reloadData]    // 刷新表单
 initWithFrame: style:UITableViewStylePlain        // 设置表单的样式, 还有一个Groupes
 -(NSInteger) numberOfSectionsInTableView:        // 返回tableView有几个分组(默认为1)
 -(CGFloat) tableView:    heightForHeaderInSection:    // 设置分组的头标高度(Section用来判断是哪个分组)
 -(CGFloat) tableView: heightForFooterInSection:    // 设置分组的脚标的高度
 -(NSInteger) tableView: numberOfRowsInSection:    // 设置一个分组中有多少行
 -(CGFloat) tableView: heightForRowAtIndexPath:    // 设置每个分组(indexPath.section)中每行(indexPath.row)的行高
 -(UITableViewCell *) tableView: cellForRowAtIndexPath:    // 一行有一个Cell, 每出现一行就执行一次这个方法
 {
   static NSString * identifier = @"cell";        // 声明一个cell的标签, 使用static即只用声明一次, 之后不再释放
   UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: identifier];    // 去cell复用池中找是否有对应标签的闲置cell, 如果找到就先手动清空原内容后再使用, 如果没有找到则实例化新的cell
   if (cell == nil)
   {
       cell = [[[UITableViewCell alloc] initWithStyle: UITabViewCellStyleSubtitle reuseIdentifier: identifier] autorelease];    // 实例化新的cell, 并给cell打上标签
   }
   cell.textLabel.text        // 设置主标题        
   cell.detailTextLabel.text    // 设置副标题(只有在Subtitle风格下才可以显示)
   cell.imageView.image        // 设置头像图片
   cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton    // 设置cell右侧按钮, 只有这种模式有点击事件
       (-(void) tableView: accessoryButtonTappedForRowWithIndexPath:    // 按钮的点击事件函数)
   cell.selectionStyle = UITableViewCellSelectionStyleGray        // 设置cell整体被点击过后的样式
 }
 // 自定义的cell要继承自UITableViewCell
 // cell本身是一个view, 在cell上面还有一个contentView, 自定义的各种控件要加在contentView上

 -(NSString *) tableView: titleForHeaderInSection:    // 设置分组头标
 -(NSString *) tableView: titleForFooterInSection:    // 设置分组脚标
 -(void) setEditing: animated:    // TableView编辑模式, 有系统提供按钮(self.editButtonItem, 只能在导航栏上, 先调用父类的此方法, 再调用自己的此方法), 也可以自定义按钮(按钮事件中使用此方法)
 -(UITableViewCellEditingStyle) tableView: editingStyleForRowAtIndexPath:    // 设置对应的行是删除还是添加操作
 -(void) tableView: commitEditingStyle: forRowAtIndexPath:    // 编辑下的添加, 删除
   都是在数据源中操作, 添加或删除数据源, 之后再执行添加或删除动画, 刷新tableView界面
   [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation: ]
   [tableView insertRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation: ]
 -(void) tableView: moveRowAtIndexPath: toIndexPath:        // 移动行, 在数据源中删除对应项, 并插入对应项
 -(void) tableView: didSelectRowAtIndexPath:            // 设置每一行点击
   [tableView deselectRowAtIndexPath: indexPath animated: YES]    // 设置自动反选, (取消点击)  
 -(void) tableView: didDeselectRowAtIndexPath:        // 设置反选时, 触发的方法, 如果在点击中设置了自动反选, 则不会触发此方法

【搜索栏】UISearchBar
   tableView.tableHeaderView = searchBar        // 设置searchBar的frame后, 加入到tableHeaderView中
【搜索控制器】UISearchDisplayController        // 搜索控制器在搜索的时候, 会自动生成一个tableView, 此时有多个tableView, 任一个tableView都会调用上面的方法, 至于是哪个tableView调用上面的方法, 需要自己判断
       [[UISearchDisplayController alloc] initWithSearchBar: searchBar contentsController: self]     // 初始化, 不要释放
   searchDisplayController.searchResultsDataSource = self;
   searchDisplayController.searchResultsDelegate = self;
 -(NSArray *) sectionIndexTitlesForTableView:        // 设置一个索引条(用数组下标和section数进行一一对应, 而不是用文字)
    搜索图标 UITableViewIndexSearch
 -(NSInteger) tableView: sectionForSectionIndexTitle: atIndex:    // 设置索引条对应关系
      [tableView scrollRectToVisible: searchBar.frame animated: YES]; return index - 1;    // 带搜索图标的对应关系

26.不同视图间的传值
 1)从A --> B (B是A的一个成员变量)
   a.定义一个B的属性, 使用属性进行传值 (最方便)
   b.重载B的init方法, 增加一个传值的参数
   c.使用NSUserDefaults
   d.使用AppDelegate
     因为AppDelegate是一个单例类, 即在整个程序中实例化的所有对象都是同一个对象, 所以可以在AppDelegate中定义一个属性, 用来在A中存值, 在B中使用.
     AppDelegate的实例化方法: AppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
 2)从B --> A (B是A的成员变量, 值返回传送, 此时用代理更方便)
   B是发送方, A是接收方; 因此在B中写协议的内容(发送方是接收方的成员变量), 并且在B中声明一个属性, 来持有这个协议, 并调用协议中的方法; A遵守此协议, 并写出B中属性的代理者为A本身(b.delegate = self)和协议中方法的实现.

27.UIPickerView
 用法类似于tableView, 也有两个协议<UIPickerViewDataSource>, <UIPickerViewDelegate>
 pickerView.dataSource = self;        pickerView.delegate = self;
 pickerView.showsSelectionIndicator = YES;
 -(NSInteger)numberOfComponentsInPickerView:    
 -(NSInteger)pickerView: numberOfRowsInComponent:
 -(NSString *)pickerView: titleForRow: forComponent:

28.UIDatePicker
 datePicker.datePickerMode = UIDatePickerModeDateAndTime; (Time, Date, CountDownTimer)        // 四种样式

29.UIAlertView
 initWithTitle: message: delegate: self cancelButtonTitle: @"Cancel" otherButtonTitles: @"OK", nil
 [alertView show]    // 显示通知
 UIAlertViewStyle (PlainTextInput, SecureTextInput, LoginAndPasswordInput)    // 通知的输入框样式
 [alertView buttonTitleAtIndex:]        // 得到按钮的title
 <UIAlertViewDelegate>
   -(void) alertView: clickedButtonAtIndex:     // 处理点击的是那个按钮
   -(void)alertViewCancel:
   -(void)willPresentAlertView:
   -(void)didPresentAlertView:
   -(void)alertView: willDismissWithButtonIndex:
   -(void)alertView: didDismissWithButtonIndex:
   -(BOOL)alertViewShouldEnableFirstOtherButton:

30.UIActionSheet
 initWithTitle: delegate:self cancelButtonTitle: destructiveButtonTitle: otherButtonTitles:, nil
 <UIActionSheetDelegate>
    -(void)actionSheet: clickedButtonAtIndex:
   -(void)actionSheetCancel:
   -(void)willPresentActionSheet:
   -(void)didPresentActionSheet:
   -(void)actionSheet: willDismissWithButtonIndex:
   -(void)actionSheet: didDismissWithButtonIndex:(NSInteger)buttonIndex;

31.iPhone文件系统
 1)Home目录的结构
   <Application Home>    (NSString *) NSHomeDirectory(); 或 [NSBundle mainBundle]
      MyApp.app    // 项目工程的目录        
      Documents    // 存储图像文档等由应用程序生成的数据        
    // [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Documents"]
    // [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
      Library        // 存储程序的用户默认设置和其他状态信息
        Caches
        Preferences
     tmp        // 存放临时文件, 重启iPhone时会丢失            
   // NSTemporaryDirectory();

32.AVAudioPlayer
 库文件AVFoundation.framework, 头文件<AVFoundation/AVFoundation.h>
 [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Burning" ofType:@"mp3"]] error:nil]        // 使用url只能播放本地文件, 使用data可以播放网络资源(但须一次性加载完, 不实用)
 player.volume                // 设置音量, 在0到1之间
 player.numberOfLoops = 2;        // 播放次数
 player.currentTime = 15.0;        // 播放开始的时间
 [player prepareToPlay]        // 加入播放队列, 一次只播放一首, 想同时播放多首, 要在不同的声道播放
 [player play]
 [player stop]

33.MPMoviePlayerController
 库文件MediaPlayer.framework,
 [[MPMoviePlayerController alloc] initWithContentURL: ]    // 这个url既可以播放本地也可以播放网络资源
 moviePlayer.movieControlStyle = MPMovieControlModeDefault;    // 设置控制器样式

 moviePlayer.scalingMode = MPMovieScalingModeAspectFit;    // 屏幕宽高比例
   // MPMovieScalingModeNone            不做任何缩放
   // MPMovieScalingModeAspectFit       适应屏幕大小,保持宽高比
   // MPMovieScalingModeAspectFill      适应屏幕大小,保持宽高比,可裁剪
   // MPMovieScalingModeFill            充满屏幕,不保持宽高比
 [moviePlayer play];
 [moviePlayer stop];

34.多语言环境
 要添加需要的语言, 系统会根据所使用系统的语言, 自动使用对应的语言
 1)系统自动生成两份XIB文件, 对应着中英文写内容
 2)手动添加几份Strings File的文件, 对应着分别放入语言文件夹中, en.lproj或zh-Hans.lproj
     文件以键值对的形式存在, "key" = "value";(不使用OC字符串, 以分号结尾)
   NSLocalizedStringFromTable(@"key", @"fileName", nil);    // 调用时使用, 第一个参数为要获得的关键字, 第二个参数为关键字所在的文件的名字, 文件都是以".strings"结尾的
   当文件名为NSLocalizable.strings时, 表示是系统缺省的名字, 使用方法NSLocalizedString(@"key", @"value");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值