ios7 programming cookbook学习笔记二

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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值