在使用UITextView时可能会遇到各种各样的效果,例如在UITextView首行前面有提示文字,并且后面输入的内容在提示的文字后面,在输入之前有默认的文字,输入过程中默认的文字会消失隐藏,具体实现代码如下:
#import "UItextviewSuoJinViewController.h"
@interface UItextviewSuoJinViewController ()
//意见内容
UITextView *contentTextView;
//在UITextView上面覆盖个UILable
UILabel *promptLabel;
}
@end
@implementation UItextviewSuoJinViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
//意见内容
contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, kHeaderHeight, kScreenWidth, 86)];
contentTextView.font = FONT(13);
contentTextView.delegate = self;
[self.view addSubview:contentTextView];
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 60, 35)];
contentLabel.font = FONT(13);
contentLabel.text = @"*您的意见";
[contentTextView addSubview:contentLabel];
//在UITextView上面覆盖个UILable
promptLabel = [[UILabel alloc] init];
promptLabel.frame =CGRectMake(5,5,200,25);
promptLabel.text = @" 请输入意见";
promptLabel.enabled = NO;
promptLabel.backgroundColor = [UIColor clearColor];
promptLabel.font = [UIFont systemFontOfSize:13];
promptLabel.textColor = RGB(245, 245, 245);
[contentTextView addSubview:promptLabel];
//改变五角星的颜色
NSMutableAttributedString *contentStr = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
[contentStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)];
contentLabel.attributedText = contentStr;
}
#pragma mark -UITextView的代理方法
-(void)textViewDidChange:(UITextView *)textView{
if (textView.text.length == 0) {
promptLabel.hidden = NO;
}else{
promptLabel.hidden = YES;
}
//首行缩进
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 3; //行间距
// paragraphStyle.maximumLine; /**最大行高*/
paragraphStyle.firstLineHeadIndent = 93.f; /**首行缩进宽度*/
paragraphStyle.alignment = NSTextAlignmentJustified;
NSDictionary *attributes = @{
NSFontAttributeName:[UIFont systemFontOfSize:13],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
}
可以将代码拷到自己的工程文件中实现看看效果。
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔