您的位置:首页 > 移动开发 > IOS开发

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

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;  注意:使用通知模式



<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios7 programming coo