问题
I am trying to show vertical scrollbar on uitextview at the beginning with the code but it isn't doing so.
UITextView *txtView=[[UITextView alloc]initWithFrame:CGRectMake(10, 80,self.view.frame.size.width-20,self.view.frame.size.height/2)];
[txtView setEditable:NO];
[txtView setSelectable:NO];
[txtView setText:self.secret];
[txtView setBackgroundColor:[UIColor clearColor]];
[txtView setTextColor:[UIColor whiteColor ]];
[txtView setFont:font];
txtView.showsVerticalScrollIndicator=YES;
[txtView flashScrollIndicators];
[self.view addSubview:txtView];
回答1:
If you just write [textView flashScrollIndicators];
it will flash only once when your textView is created or page is loaded. There is not any code or method which display flashScrollIndicators
continuously/permanently.
For do it you need to take help of NSTimer
with very low time interval, and write code of flash indicator of textView in method of the timer. such like
[NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector:@selector(flashIndicator) userInfo:nil repeats:YES]; // set time interval as per your requirement.
call method
-(void)flashIndicator
{
//here you need to write code:
[txtView flashScrollIndicators];
}
For more clarify:
UITextView comes under UIScrollView class. So there is a method flashScrollIndicators that you can call to prompts the user that the view is scrollable. It only flashes once for few seconds where user comes to a page that contains UIScrollView or its subclass. You may set timer to call this method more than one time.
回答2:
You can use setContentSize property for this. By setting it larger than the textview you can se scrolling indicators.
来源:https://stackoverflow.com/questions/23236409/uitextview-show-vertical-scrollbar-all-the-time