2012-03-09 78 views
0
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)]autorelease]; 

self.textView.textColor = [UIColor whiteColor]; 

self.textView.font = [UIFont fontWithName:@"Georgia-BoldItalic" size:14]; 

self.textView.backgroundColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0]; 

[self.textView flashScrollIndicators]; 

self.textView.showsHorizontalScrollIndicator = YES; 

self.textView.scrollEnabled = YES; 

self.textView.layer.borderWidth = 1; 

self.textView.layer.borderColor = [[UIColor whiteColor] CGColor]; 

self.textView.layer.cornerRadius = 1; 

self.textView.textAlignment = UITextAlignmentCenter; 

什么我为在这里失踪,为的UITextView显示滚动条或者使TextView的scrollenabled。UITextView中没有显示scrollindicator

欣赏帮助。

+0

您的textview滚动只是没有显示指标,或者根本不滚动。 – NJones 2012-03-10 19:48:22

回答

0

self.textView.showsVerticalScrollIndicator = YES;

这是你在找什么?

+0

Still scrollindicator未显示 – user1120133 2012-03-09 23:43:35

+0

UITextView中是否有足够的文本允许滚动? – tallybear 2012-03-09 23:46:10

+0

我有一个很长的textview内容 – user1120133 2012-03-09 23:49:20

0

文本视图是键盘下方。只有输入了足够的文字才能填充所有看不到的行,并且即使这样,也无法将其全部滚动到视图中。要正确执行此操作,您需要听取键盘大小调整通知并调整文本视图大小以适应可见空间。创建文本视图之后,订阅键盘调整的通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 

然后实现这些方法:

- (void)keyboardDidShow:(NSNotification*)notification 
{ 
    NSValue* val = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGRect keyboardRect = [[self.view window] convertRect:[val CGRectValue] toView:self.textView]; 

    CGRect rect = self.textView.frame; 
    rect.size.height = CGRectGetMinY(keyboardRect); 
    self.textView.frame = rect; 
} 

- (void)keyboardWillHide:(NSNotification *)notification 
{ 
    self.textView.frame = CGRectMake(0, 0, 320, 416); 
} 

最后,如果订阅了通知(视图控制器,我的目标假设)将在应用程序的生命周期的任何时间点消失,您还需要在它处理之前取消订阅。 (即使不是这样,因为这是一个很好的做法。)

- (void)dealloc 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 

    // ... 

    [super dealloc]; 
}