UITextview show vertical scrollbar all the time

╄→гoц情女王★ 提交于 2020-04-10 06:02:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!