怎样让UITextView可以首字显示标点符号
1个回答
展开全部
让UITextView和UITextField同样拥有垂直居中的属性,建议单独一个类继承自UITextView
只需要初始化UITextView之后用KVO监听 "contentSize" 属性即可
_textView = [[UITextView alloc] initWithFrame:CGRectMake(20.0f, DOT_COORDINATE,260.0f, TABLE_VIEW_ROW_HEIGHT*2)];
_textView.delegate = self;
_textView.text = PROMPT_TEXT;
_textView.font = [UIFont systemFontOfSize:18.0f];
_textView.textColor = [UIColor lightGrayColor];
[self.contentView addSubview:_textView];
[_textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
UITextView *tv = object;
// Center vertical alignment
CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height * [tvzoomScale])/2.0;
topCorrect = ( topCorrect < 0.0 ? 0.0 : topCorrect );
tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
// // Bottom vertical alignment
// CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height);
// topCorrect = (topCorrect <0.0 ? 0.0 : topCorrect);
// tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}
只需要初始化UITextView之后用KVO监听 "contentSize" 属性即可
_textView = [[UITextView alloc] initWithFrame:CGRectMake(20.0f, DOT_COORDINATE,260.0f, TABLE_VIEW_ROW_HEIGHT*2)];
_textView.delegate = self;
_textView.text = PROMPT_TEXT;
_textView.font = [UIFont systemFontOfSize:18.0f];
_textView.textColor = [UIColor lightGrayColor];
[self.contentView addSubview:_textView];
[_textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
UITextView *tv = object;
// Center vertical alignment
CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height * [tvzoomScale])/2.0;
topCorrect = ( topCorrect < 0.0 ? 0.0 : topCorrect );
tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
// // Bottom vertical alignment
// CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height);
// topCorrect = (topCorrect <0.0 ? 0.0 : topCorrect);
// tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect};
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询