ios7 programming cookbook学习笔记二
2014-05-30 17:16
113 查看
1 UILabel 定制 常用属性
shadowColor shadowOffset numberOfLines lineBreakMode textAlignment textColor font adjustsFontSizeToFitWidth
2 UITextField 在Interface Builder中你拖拽过来的textfield高度是没法改变的(31个像素高),不过用纯代码的方式定义的话可以改变其高度,但是其行数只能是1行。
常用属性:borderStyle:边框式样 contentVerticalAlignment :内容垂直方向的对齐方式 textAlignment:内容水平方向的对齐方式 placeholder:占位符,起到提示的作用
* UITextField还有两个重要属性:leftView和rightView
UITextFieldDelegate分析
textFieldShouldBeginEditing: 是否允许编辑
textFieldDidBeginEditing: 开始编辑后调用
textFieldShouldEndEditing: 是否允许结束编辑
textFieldDidEndEditing: 编辑结束后调用
textField:shouldChangeCharactersInRange:replacementString: 是否允许自动更正
textFieldShouldClear: 这个确定是否显示那个“x”号的删除按钮
textFieldShouldReturn: 这个是决定当你按下return按钮是的动作
UIKeyboardWillShowNotification 键盘出来前触发该通知
Gets sent by the system whenever the keyboard is brought up on the screen for any component, be it a text field, a text view, etc.
UIKeyboardDidShowNotification 键盘出来后触发这个通知
Gets sent by the system when the keyboard has already been displayed.
UIKeyboardWillHideNotification 键盘将要消失时调用这个通知
Gets sent by the system when the keyboard is about to hide.
UIKeyboardDidHideNotification 键盘消失后调用这个通知
Gets sent by the system when the keyboard is now fully hidden.
在uitextview下编辑时,弹出的键盘会遮盖很大一部分,当我们输入的内容较多时,很不方便,那如何解决呢?方法如下:
思想:在键盘弹出前、消失后分别改变contentInset属性,当键盘弹出前,self.myTextView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f,keyboardRect.size.height, 0.0f);
在键盘消失后:self.myTextView.contentInset = UIEdgeInsetsZero; 注意:使用通知模式
4
UIViewContentModeScaleToFill 按照比例来缩放图片,以适应视图的边界大小
UIViewContentModeScaleAspectFit 以合适的比率使图片适应视图
5 富文本 NSMutableAttributedString
setAttri butes:range:
第一个参数是个字典,这里总结一下常用的关键字:NSFontAttributeName NSForegroundColorAttributeName NSBackgroundColorAttributeName NSShadowAttributeName
第二个参数是范围:range 起始位置和长度
示例代码:<span style="font-size:18px;">NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor darkGrayColor];
shadow.shadowOffset = CGSizeMake(4.0f, 4.0f);
NSDictionary *attributesForSecondWord = @{
NSFontAttributeName : [UIFont boldSystemFontOfSize:60.0f],
NSForegroundColorAttributeName : [UIColor whiteColor],
NSBackgroundColorAttributeName : [UIColor redColor],
NSShadowAttributeName : shadow
};</span>
shadowColor shadowOffset numberOfLines lineBreakMode textAlignment textColor font adjustsFontSizeToFitWidth
2 UITextField 在Interface Builder中你拖拽过来的textfield高度是没法改变的(31个像素高),不过用纯代码的方式定义的话可以改变其高度,但是其行数只能是1行。
常用属性:borderStyle:边框式样 contentVerticalAlignment :内容垂直方向的对齐方式 textAlignment:内容水平方向的对齐方式 placeholder:占位符,起到提示的作用
* UITextField还有两个重要属性:leftView和rightView
UILabel *currencyLabel = [[UILabel alloc] initWithFrame:CGRectZero]; currencyLabel.text = [[[NSNumberFormatter alloc] init] currencySymbol]; currencyLabel.font = self.myTextField.font; [currencyLabel sizeToFit]; self.myTextField.leftView = currencyLabel; self.myTextField.leftViewMode = UITextFieldViewModeAlways; 结构如图:
UITextFieldViewMode: typedef NS_ENUM(NSInteger, UITextFieldViewMode) { UITextFieldViewModeNever, UITextFieldViewModeWhileEditing, UITextFieldViewModeUnlessEditing, UITextFieldViewModeAlways };
UITextFieldDelegate分析
textFieldShouldBeginEditing: 是否允许编辑
textFieldDidBeginEditing: 开始编辑后调用
textFieldShouldEndEditing: 是否允许结束编辑
textFieldDidEndEditing: 编辑结束后调用
textField:shouldChangeCharactersInRange:replacementString: 是否允许自动更正
textFieldShouldClear: 这个确定是否显示那个“x”号的删除按钮
textFieldShouldReturn: 这个是决定当你按下return按钮是的动作
3 UITextView
比如说textfield、textview等会调用键盘,这样会触发一下函数:UIKeyboardWillShowNotification 键盘出来前触发该通知
Gets sent by the system whenever the keyboard is brought up on the screen for any component, be it a text field, a text view, etc.
UIKeyboardDidShowNotification 键盘出来后触发这个通知
Gets sent by the system when the keyboard has already been displayed.
UIKeyboardWillHideNotification 键盘将要消失时调用这个通知
Gets sent by the system when the keyboard is about to hide.
UIKeyboardDidHideNotification 键盘消失后调用这个通知
Gets sent by the system when the keyboard is now fully hidden.
在uitextview下编辑时,弹出的键盘会遮盖很大一部分,当我们输入的内容较多时,很不方便,那如何解决呢?方法如下:
思想:在键盘弹出前、消失后分别改变contentInset属性,当键盘弹出前,self.myTextView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f,keyboardRect.size.height, 0.0f);
在键盘消失后:self.myTextView.contentInset = UIEdgeInsetsZero; 注意:使用通知模式
4
<span style="font-size:18px;">typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, };</span>解释
UIViewContentModeScaleToFill 按照比例来缩放图片,以适应视图的边界大小
UIViewContentModeScaleAspectFit 以合适的比率使图片适应视图
5 富文本 NSMutableAttributedString
setAttri butes:range:
第一个参数是个字典,这里总结一下常用的关键字:NSFontAttributeName NSForegroundColorAttributeName NSBackgroundColorAttributeName NSShadowAttributeName
第二个参数是范围:range 起始位置和长度
示例代码:<span style="font-size:18px;">NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor darkGrayColor];
shadow.shadowOffset = CGSizeMake(4.0f, 4.0f);
NSDictionary *attributesForSecondWord = @{
NSFontAttributeName : [UIFont boldSystemFontOfSize:60.0f],
NSForegroundColorAttributeName : [UIColor whiteColor],
NSBackgroundColorAttributeName : [UIColor redColor],
NSShadowAttributeName : shadow
};</span>
相关文章推荐
- 如何使用KeyChain保存和获取UDID。iOS7获取唯一标示符的方法
- [cocos2d-x 2.0.4][iOS7]图片加载错误
- iOS7滑动返回
- iOS7滑动返回
- 【iOS7开发快速入门】代码示例3-10
- UISearchBar去掉背景的方法(分为ios7以前和ios7以后)
- iOS7 Programming Cookbook-Chapter 7-Concurrency(Operation)
- iOS7 iOS8 毛玻璃效果的分别实现
- iOS7新特性适配
- ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题
- 关于iOS7以后版本企业发布问题
- 解决XCode6在IOS7系统上出现部分黑屏与不适配问题
- 逐步整理IOS7、8、9 以及后续无限的版本
- [ios]关于程序在ios7与ios8运行对分辨率的判断会出错的问题
- [ UIScreen mainScreen ].bounds;在IOS7和IOS8的区别
- iOS7 UIWebView内存泄露问题解决方法
- 安卓自定义日期控件(仿QQ,IOS7)
- UITableViewCell 在IOS7的父视图是UITableViewWrapperView。
- (4/18)重学Standford_iOS7开发_框架和带属性字符串_课程笔记
- 安卓自定义日期控件(仿QQ,IOS7)续