Latest 0.0.8
Homepage https://github.com/lele8446/TextViewDemo
License Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Platforms ios 7.0
Authors

简介

自定义UITextView:

  • 1、添加placeHold提示
  • 2、输入时可插入不可编辑的自定义文本(如#主题#,@人名);
  • 3、UITextView高度可根据输入内容动态调整


引用到项目中

文件引用

下载demo后直接把CJUITextView文件夹添加到项目中

cocoapods安装

  • Podfile
    platform :ios, '7.0'
    pod 'CJTextView', '~> 0.0.3'

属性介绍

/**
 *  placeHold提示内容Insets值(default (4, 4, 4, 4))
 */
@property (nonatomic, assign, setter=setPlaceHoldContainerInset:) UIEdgeInsets placeHoldContainerInset;
/**
 *  是否根据输入内容自动调整高度(default NO)
 */
@property (nonatomic, assign, setter=setAutoLayoutHeight:) BOOL autoLayoutHeight;
/**
 *  autoLayoutHeight为YES时的最大高度(default MAXFLOAT)
 */
@property (nonatomic, assign) CGFloat maxHeight;
/**
 *  插入文本的颜色(default self.textColor)
 */
@property (nonatomic, strong, getter=getSpecialTextColor) UIColor *specialTextColor;
/**
 *  插入文本是否可编辑(default NO)
 */
@property (nonatomic, assign) BOOL enableEditInsterText;

调用方法

  /**
   *  在指定位置插入字符,并返回插入字符后的SelectedRange值
   *
   *  @param specialText    要插入的字符
   *  @param selectedRange  插入位置
   *  @param attributedText 插入前的文本
   *
   *  @return 插入字符后的光标位置
   */
  - (NSRange)insterSpecialTextAndGetSelectedRange:(NSAttributedString *)specialText
                                  selectedRange:(NSRange)selectedRange
                                           text:(NSAttributedString *)attributedText;

调用示例:

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"#插入文本#"];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, str.length)];
    [self.textView insterSpecialTextAndGetSelectedRange:str selectedRange:self.textView.selectedRange text:self.textView.attributedText];

Latest podspec

{
    "name": "CJTextView",
    "version": "0.0.8",
    "summary": "u81eau5b9au4e49UITextView",
    "homepage": "https://github.com/lele8446/TextViewDemo",
    "license": {
        "type": "Apache License, Version 2.0",
        "text": "    Licensed under the Apache License, Version 2.0 (the "License");n    you may not use this file except in compliance with the License.n    You may obtain a copy of the License atnn    http://www.apache.org/licenses/LICENSE-2.0nn    Unless required by applicable law or agreed to in writing, softwaren    distributed under the License is distributed on an "AS IS" BASIS,n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.n    See the License for the specific language governing permissions andn    limitations under the License.n"
    },
    "authors": {
        "lele8446": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/lele8446/TextViewDemo.git",
        "tag": "0.0.8"
    },
    "source_files": "CJUITextView/*"
}

Pin It on Pinterest

Share This