UITextView设置文字垂直居中和LinkAttribute
来源:互联网 发布:深入理解linux内核pdf 编辑:程序博客网 时间:2024/05/01 15:41
UITextView设置文字垂直居中和LinkAttribute
想要几行文字居中对齐的实现方式有多种,如使用:UILabel,UITextField,UITextView。以下是UITextView的简单使用。
NSMutableDictionary *ornamentAttributes = [NSMutableDictionary dictionary]; NSMutableParagraphStyle *ornamentParagraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; //设置text文字垂直居中 ornamentParagraph.alignment = NSTextAlignmentCenter; //设置行间距 ornamentParagraph.lineSpacing = 5; ornamentAttributes[NSParagraphStyleAttributeName] = ornamentParagraph; //整个字符串的样式 NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:17],NSParagraphStyleAttributeName: ornamentParagraph, NSForegroundColorAttributeName: UIColorFromRGB(0x7dd4f2)}; //设置可点击字符串的Attributes NSDictionary *linkAttributes = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSLinkAttributeName: @"1", NSForegroundColorAttributeName: [UIColor whiteColor]}; //初始化字符串 NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"注册使用XXXXX,就表示您同意\nXXXXX的用户协议"] attributes: attributes]; [content addAttributes:linkAttributes range: NSMakeRange(content.length - 4, 4)]; self.textView.editable = NO; self.textView.linkTextAttributes = linkAttributes; self.textView.delegate = self;//设置UITextView的代理为self self.textView.attributedText = content; self.textView.backgroundColor = [UIColor clearColor]; [self.view addSubview:_textView];
实现UITextViewDelegate的代理方法:
- (BOOL) textView:(UITextView )textView shouldInteractWithURL:(NSURL )URL inRange:(NSRange)characterRange
- (BOOL) textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { ... ... do some thing; ... ... return YES;}
0 0
- UITextView设置文字垂直居中和LinkAttribute
- 让UITextView文字垂直居中
- UITextView 文字莫名其妙垂直居中解决办法
- UITextView垂直居中和自动扩充
- 图片和文字垂直居中
- ios UITextView 垂直居中
- UITextView内容垂直居中
- UIButton 设置图片文字垂直居中排列
- 关于文字垂直居中的设置
- CSS 设置导航栏文字的垂直居中和水平居中
- CSS设置水平居中和垂直居中
- UITextView 单行垂直居中显示
- iOS UITextView 垂直水平居中
- div内文字和控件垂直居中
- 文字和图片垂直居中问题
- 图片和文字垂直居中的方法
- css 图片和文字同时垂直居中
- css-图片和文字垂直居中问题
- LinkedHashMap与TreeMap浅析
- ImageView centerInside时setImageBitmap图片过小的解决方式
- PostgreSQL之日期字段统一加一天
- Dynamics Unified Service Desk 技术分享资源汇总(工具,文档)
- map的引用传递浅谈
- UITextView设置文字垂直居中和LinkAttribute
- JSON页面间传值问题
- c# .net orm 框架 dapper.net 的应用
- 总结程序员成长的几个阶段的心态
- Web前端 之 RequireJS
- DiskFileItemFactory类
- 设计师们值得一试的十款用户体验工具
- VS创建Qt4应用程序后如何生成.ui文件的ui_XXX.h文件
- Android四大基本组件介绍与生命周期