iPhone的UI标准和基本UI控.ppt

上传人:max****ui 文档编号:6353977 上传时间:2020-02-23 格式:PPT 页数:40 大小:3.70MB
返回 下载 相关 举报
iPhone的UI标准和基本UI控.ppt_第1页
第1页 / 共40页
iPhone的UI标准和基本UI控.ppt_第2页
第2页 / 共40页
iPhone的UI标准和基本UI控.ppt_第3页
第3页 / 共40页
点击查看更多>>
资源描述
iPhone的基本UI控件使用 iPhone系统标准UI UI控件使用 通过上节课的介绍 大家对于iPhone的整个框架和语法有了大致了解 本节课程将具体介绍iPhone的UI标准和UIView上的UI子控件 上节回顾 iPhone系统标准UI介绍UI规范输入控件 UITextField UITextView 按钮控件 UIButton UIControl 控制控件 UISwitch UISlider 进度条 UIActivityIndicatorView UIProgressView 提示控件 UIAlertSheet UIActionSheet 导航条和工具条控件 UINavigationBar UIToolBar UISegment 参考代码 UICatalog 课程大纲 iPhone系统标准UI介绍 UI规范 继承树 UIControl UIView UIResponder NSObject描述 UITextField是控制单行输入的控件 用于简单的输入场合 如QQ昵称 对话框输入等 讨论主题 键盘控制 显示控制 文字控制 UITextField属性 文本属性 Text 文字内容placeHolder 空填充的文字内容Font 字体类型textColor 文本颜色textAlignment 文本对齐方式adjustsFontSizeToFitWidth 是否自适应文字大小minimumFontSize 最小文字号数边框属性borderStyle 边框风格background 背景Clearmode 清除模式leftView rightView 左右边视图 UITextField的属性 编辑属性 DelegateeditingclearsOnBeginEditing方法 textRectForBounds drawTextInRect placeholderRectForBounds drawPlaceholderInRect borderRectForBounds editingRectForBounds clearButtonRectForBounds leftViewRectForBounds rightViewRectForBounds Delegate BOOL textFieldShouldBeginEditing 返回NO讲禁止编辑 void textFieldDidBeginEditing 当键盘得到焦点的时候 调用此方法 BOOL textFieldShouldEndEditing 如果返回NO将会限制键盘掉下 void textFieldDidEndEditing 键盘已经掉下 BOOL textField UITextField textFieldshouldChangeCharactersInRange NSRange rangereplacementString NSString string 返回no输入字符无效 BOOL textFieldShouldClear UITextField textField BOOL textFieldShouldReturn UITextField textField NotificationUITextFieldTextDidBeginEditingNotification UITextFieldTextDidEndEditingNotification UITextFieldTextDidChangeNotification UITextView 继承树 UIScrollView UIView UIResponder NSObject描述 UITextView是相对复杂可用作多行输入的控件属性 textpropertyfontpropertytextColorpropertyeditablepropertydataDetectorTypespropertytextAlignmentpropertyselectedRangeproperty方法 hasText scrollRangeToVisible 通告 UITextViewTextDidBeginEditingNotificationUITextViewTextDidChangeNotificationUITextViewTextDidEndEditingNotification Delegate BOOL textViewShouldBeginEditing UITextView textView BOOL textViewShouldEndEditing UITextView textView void textViewDidBeginEditing UITextView textView void textViewDidEndEditing UITextView textView BOOL textView UITextView textViewshouldChangeTextInRange NSRange rangereplacementText NSString text void textViewDidChange UITextView textView void textViewDidChangeSelection UITextView textView UIButton 继承树 UIControl UIView UIResponder NSObject讨论主题 button是什么 怎么创建button怎么使用button 什么是button 创建方式 buttonWithType initWithFrame 配置buttonbuttonTypeFontlinebreakMode 当标题或者图片超过frame大小时采取的截断方式 3 x以后不用此属性 titleShadhowOffset 阴影的偏移量 3 x后不用此属性 怎么创建button setTitle forState setTitleColor forState setTitleShadowColor forState titleColorForState titleForState titleShadowColorForState 标题文字操作 设置状态 adjustsImageWhenHighlightedpropertyadjustsImageWhenDisabledpropertyshowsTouchWhenHighlightedproperty Highlighted表示点击后的状态 forState通常这个state我可以设置为UIContrlStateNormal 如果点击后需要做还图片的操作 我们可以设置UIControlStateHeightLight的图片 imageForState setBackgroundImage forState setImage forState 设置边框contentEdgeInsetspropertytitleEdgeInsetspropertyimageEdgeInsetsproperty 设置边距使用UIEdgeInsets结构体 分别设置其上下左右的位置即可 图片操作 添加事件 buttonaddTarget targetaction selectorforControlEvents UIControlEventTouchUpInside target 处理该事件的对象selector target需要调用的响应函数event 响应哪种事件事件类型 UIControlEventTouchDown onalltouchdownsUIControlEventTouchDownRepeat onmultipletouchdowns tapcount 1 UIControlEventTouchDragInside 内部拖动UIControlEventTouchDragOutside 外部拖动UIControlEventTouchUpInside 手指点击在按钮内抬起UIControlEventTouchUpOutside 手指点击拖动到按钮之外 抬起UIControlEventTouchCancel 系统事件抢占了当前的点击事件 如来电 或者另外手指点击了会退按钮 UIControlEventValueChanged UISwitchUIControlEventEditingDidBegin UITextField 添加事件 UIControlEventEditingChangedUIControlEventEditingDidEndUIControlEventEditingDidEndOnExitUIControlEventAllTouchEventsUIControlEventAllEditingEventsUIControlEventApplicationReserved 下面两个系统用UIControlEventSystemReserved Button使用示例 继承树 UIView UIResponder NSObject描述 UIControl封装了触摸类型的接收和消息的分发操作 是UIButton UISlider UITextField的父类 讨论内容 UIControl的使用时机UIControl的常见问题 UIControl 通常像到用户点击某个区域响应 对应的点击事件 我们会用到UIButton 但是 UIButton有一些默认的处理比如点击按钮后 按钮会变灰 弹起来时又恢复 如果要做下图的效果 UIControl的使用时机 在我的秀 消息 好友 我们很显然可以在UIControl上加Label来完成 UITextField输入焦点没有居中问题 contentVerticalAlignmentcontentHorizontalAlignmentUIControl加到UIScrollView上失效的问题 因为UIControl和UIScrollView都是继承自UIResponder 他们对UIResponder的事件都作了处理 在消息循环中只有一个对象可以处理消息 所以会导致失效 这时可以用UIView来处理 UIControl常见问题 UISwithandUISlider 创建CGRectframe CGRectMake 198 0 12 0 94 0 27 0 switchCtl UISwitchalloc initWithFrame frame switchCtladdTarget selfaction selector switchAction forControlEvents UIControlEventValueChanged switchCtl backgroundColor UIColorclearColor 使用 void switchAction UISwitch sw if sw on else UISwitch的创建和使用 创建sliderCtl UISlideralloc initWithFrame frame sliderCtladdTarget selfaction selector sliderAction forControlEvents UIControlEventValueChanged sliderCtl backgroundColor UIColorclearColor sliderCtl minimumValue 0 0 sliderCtl maximumValue 100 0 sliderCtl continuous YES sliderCtl value 50 0 使用 void SliderAction UISlider s Object alpha S value 100 0f UISlider的创建和使用 UIActivityIndicatorView UIProgressView progressInd UIActivityIndicatorViewalloc initWithFrame frame progressIndstartAnimating progressInd activityIndicatorViewStyle UIActivityIndicatorViewStyleGray progressIndsizeToFit UIActivityIndicatorView progressBar UIProgressViewalloc initWithFrame frame progressBar progressViewStyle UIProgressViewStyleDefault progressBar progress 0 5 progress从0 0 1 0 UIProgressView UIAlertView UIAlertSheet 说明UIAlertView相当于windows中的提示框UIActionSheet相当于windows中的菜单项使用UIAlertView alert UIAlertViewalloc initWithTitle UIAlertView message delegate selfcancelButtonTitle Cancel otherButtonTitles OK nil alertshow alertrelease UIActionSheet actionSheet UIActionSheetalloc initWithTitle UIActionSheet delegate selfcancelButtonTitle Cancel destructiveButtonTitle OK otherButtonTitles nil actionSheet actionSheetStyle UIActionSheetStyleDefault actionSheetshowInView self view actionSheetrelease UIAlertView UIAlertViewdelegateUIActionSheetDelegate 事件处理 UINavigationBar UIBarButtonItem UINavigationBar是导航条控件 在iPhone上因为屏幕有限 所以出现了由导航条控制的层级目录浏览方式 其中 UINavigationBar只是一个组织管理的容器 而显示和其上的事件添加由UINavigationItem来管理 UINavigationItem中又有left和right连个Item以及titleView用来自定义中间的标题栏 讨论的主题 UINavigationBar的创建和使用例子 navBarTest UIToolBar UIToolBar像windows中的浮动菜单 它的样式和UINavigationBar很像 同的是它并不像UINavigationBar一样有一个stack的结构可以存储多级的item 它永远只是一级的平面结构 还有一点不同的是它可以放多个item UINavigationItem通常左右一个item中间一个标题 在使用分格上UINavigationItem通常放在顶部 UIToolBar可任意放置 UISegmentView用来显示单选的一种控件 在我们的项目中上一页 下一页是最常用这个控件 UISegmentedControl segmentedControl UISegmentedControlalloc initWithItems NSArrayarrayWithObjects UIImageimageNamed segment check png UIImageimageNamed segment search png UIImageimageNamed segment tools png nil segmentedControl frame frame segmentedControladdTarget selfaction selector segmentAction forControlEvents UIControlEventValueChanged segmentedControl segmentedControlStyle UISegmentedControlStylePlain segmentedControl selectedSegmentIndex 1 self viewaddSubview segmentedControl segmentedControlrelease
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!