iOS设置textView的行间距
2016-01-27 12:28
573 查看
- (void)viewDidLoad {
[super
viewDidLoad];
UITextView *textView = [[UITextView
alloc] initWithFrame:CGRectMake(50,
200, 150,
250)];
textView.delegate =
self;
textView.layer.borderWidth =
1.0f;
textView.layer.borderColor = [UIColor
blackColor].CGColor;
// 1.静态显示textView的内容为设置的行间距,执行如下代码:
// textview
改变字体的行间距
// NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// paragraphStyle.lineSpacing = 5;//
字体的行间距
//
// NSDictionary *attributes = @{
// NSFontAttributeName:[UIFont systemFontOfSize:15],
// NSParagraphStyleAttributeName:paragraphStyle
// };
// textView.attributedText = [[NSAttributedString alloc] initWithString:@"1、输入你的内容,如果只是静态显示textView的内容为设置的行间距,执行如下代码。2、输入你的内容,如果只是静态显示textView的内容为设置的行间距,执行如下代码"
attributes:attributes];
[self.view
addSubview: textView];
}
// 2.如果是想在输入内容的时候就按照设置的行间距进行动态改变,那就需要将上面代码放到textView的delegate方法里
-(void)textViewDidChange:(UITextView *)textView
{
// textview
改变字体的行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle
alloc]
init];
paragraphStyle.lineSpacing =
15;// 字体的行间距
NSDictionary *attributes =
@{
NSFontAttributeName:[UIFont
systemFontOfSize:17],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString
alloc] initWithString:textView.text
attributes:attributes];
}
[super
viewDidLoad];
UITextView *textView = [[UITextView
alloc] initWithFrame:CGRectMake(50,
200, 150,
250)];
textView.delegate =
self;
textView.layer.borderWidth =
1.0f;
textView.layer.borderColor = [UIColor
blackColor].CGColor;
// 1.静态显示textView的内容为设置的行间距,执行如下代码:
// textview
改变字体的行间距
// NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// paragraphStyle.lineSpacing = 5;//
字体的行间距
//
// NSDictionary *attributes = @{
// NSFontAttributeName:[UIFont systemFontOfSize:15],
// NSParagraphStyleAttributeName:paragraphStyle
// };
// textView.attributedText = [[NSAttributedString alloc] initWithString:@"1、输入你的内容,如果只是静态显示textView的内容为设置的行间距,执行如下代码。2、输入你的内容,如果只是静态显示textView的内容为设置的行间距,执行如下代码"
attributes:attributes];
[self.view
addSubview: textView];
}
// 2.如果是想在输入内容的时候就按照设置的行间距进行动态改变,那就需要将上面代码放到textView的delegate方法里
-(void)textViewDidChange:(UITextView *)textView
{
// textview
改变字体的行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle
alloc]
init];
paragraphStyle.lineSpacing =
15;// 字体的行间距
NSDictionary *attributes =
@{
NSFontAttributeName:[UIFont
systemFontOfSize:17],
NSParagraphStyleAttributeName:paragraphStyle
};
textView.attributedText = [[NSAttributedString
alloc] initWithString:textView.text
attributes:attributes];
}
相关文章推荐
- ios开发-格式转换
- iOS开发-修改TableViewCell的Delete按钮
- iOS统计数组相同元素的个数(使用数组筛选计算)
- [iOS]修改开发者中心Bundle Identifier的一些配置
- iOS 视图左右晃动动画
- iphone ios 如何使用gcd,block
- iOS中的协议与委托
- iOS开发-进阶:企业级应用Plist文件模板
- iOS开发-工具:Xcode7 做ipa企业级分发(In-House模式)详细步骤
- iOS开发-进阶:长按手势执行两次解决办法
- XCode对自带的SVN操作
- ios客户端websocket的helloworld
- ios集成支付宝 报错 rsa_private read error : private key is NULL解决方法
- iOS开发-进阶:MOV格式视频转MP4格式
- iOS7 NavigationController 右滑手势失效问题
- iOS开发-基础:获取指定路径文件大小
- [iOS]iPhone上传项目遇到的问题
- IOS 跳转页面
- iOS视频背景视图
- iOS开发-基础:数据类型