UITextView 单行垂直居中显示
来源:互联网 发布:报表编程软件 编辑:程序博客网 时间:2024/04/29 06:04
[textView addObserver:selfforKeyPath:@"contentSize"options:NSKeyValueObservingOptionNewcontext:nil];//也可以监听contentSize属性
//接收处理
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
UITextView *mTrasView = object;
CGFloat topCorrect = ([mTrasView bounds].size.height - [mTrasView contentSize].height);
topCorrect = (topCorrect <0.0 ?0.0 : topCorrect);
mTrasView.contentOffset = (CGPoint){.x =0, .y = -topCorrect/2};
textView.font = [UIFont systemFontOfSize:17];
textView.textColor = [UIColor whiteColor];
CGSize singleSize = [@"你好" sizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(textView.frame.size.width,MAXFLOAT)];
CGSize textSize = [mTrasView.text sizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(textView.frame.size.width,MAXFLOAT)];
NSInteger lines = textSize.height / singleSize.height;
if (lines > 1) {
textView.textAlignment = NSTextAlignmentLeft;
}else {
textView.textAlignment = NSTextAlignmentCenter;
}
}
- UITextView 单行垂直居中显示
- CEdit 单行垂直居中显示
- CSS 单行垂直居中
- 单行多行中垂直居中
- ios UITextView 垂直居中
- UITextView内容垂直居中
- Edit控件单行显示文字垂直居中的办法
- 让UITextView文字垂直居中
- iOS UITextView 垂直水平居中
- 单行图文混排垂直居中
- CEdit 文本垂直居中(单行解决方案)
- 【MFC】单行CEdit文本的“垂直居中”
- 【CSS】单行图片与文字垂直居中
- 使UITextView中的内容 垂直居中
- UITextView垂直居中和自动扩充
- 使UITextView中的内容 垂直居中
- UITextView 文字莫名其妙垂直居中解决办法
- UITextView设置文字垂直居中和LinkAttribute
- hibernate jar包详解
- 关于单例设计模式
- socket
- python网络爬虫
- AVPlayer
- UITextView 单行垂直居中显示
- Allegro:Arc segment is outside of the extents.
- java 内部类总结
- 整数问题及位运算的一些总结
- Spring -- Model 和 ModelAndView
- 高效程序员的45个习惯
- 数据库资源消耗高时两条简单管用、快速找出可能问题原因的SQL语句
- 一些常用软件的网络端口协议分类介绍
- FFplay 播放器