<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 一:效果 ![](https://box.kancloud.cn/2016-01-20_569f1d99ca889.jpg) ## 二:代碼: 由于系統自帶的UITextField:和UITextView:不能滿足我們的需求,所以我們需要自己設計一個。 UITextField:? 1.文字永遠是一行,不能顯示多行文字? 2.有placehoder屬性設置占位文字? 3.繼承自UIControl? 4.監聽行為? 1> 設置代理? 2> addTarget:action:forControlEvents:? 3> 通知:UITextFieldTextDidChangeNotification UITextView:? 1.能顯示任意行文字? 2.不能設置占位文字? 3.繼承自UIScollView? 4.監聽行為? 1> 設置代理? 2> 通知:UITextViewTextDidChangeNotification ### NYTextView.h ~~~ // // Created by apple on 14-10-20. // Copyright (c) 2014年 heima. All rights reserved. // 增強:帶有占位文字 #import <UIKit/UIKit.h> @interface NYTextView : UITextView /** 占位文字 */ @property (nonatomic, copy) NSString *placeholder; /** 占位文字的顏色 */ @property (nonatomic, strong) UIColor *placeholderColor; @end ~~~ ### NYTextView.m ~~~ // Created by apple on 14-10-20. // Copyright (c) 2014年 heima. All rights reserved. // #import "NYTextView.h" @implementation NYTextView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // 不要設置自己的delegate為自己 // self.delegate = self; // 通知 // 當UITextView的文字發生改變時,UITextView自己會發出一個UITextViewTextDidChangeNotification通知 [NYNotificationCenter addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self]; } return self; } - (void)dealloc { [NYNotificationCenter removeObserver:self]; } /** * 監聽文字改變 */ - (void)textDidChange { // 重繪(重新調用) [self setNeedsDisplay]; } - (void)setPlaceholder:(NSString *)placeholder { _placeholder = [placeholder copy]; [self setNeedsDisplay]; } - (void)setPlaceholderColor:(UIColor *)placeholderColor { _placeholderColor = placeholderColor; [self setNeedsDisplay]; } - (void)setText:(NSString *)text { [super setText:text]; // setNeedsDisplay會在下一個消息循環時刻,調用drawRect: [self setNeedsDisplay]; } - (void)setFont:(UIFont *)font { [super setFont:font]; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { // [NYRandomColor set]; // UIRectFill(CGRectMake(20, 20, 30, 30)); // 如果有輸入文字,就直接返回,不畫占位文字 if (self.hasText) return; // 文字屬性 NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = self.font; attrs[NSForegroundColorAttributeName] = self.placeholderColor?self.placeholderColor:[UIColor grayColor]; // 畫文字 // [self.placeholder drawAtPoint:CGPointMake(5, 8) withAttributes:attrs]; CGFloat x = 5; CGFloat w = rect.size.width - 2 * x; CGFloat y = 8; CGFloat h = rect.size.height - 2 * y; CGRect placeholderRect = CGRectMake(x, y, w, h); [self.placeholder drawInRect:placeholderRect withAttributes:attrs]; } @end ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看