設置UITextView的垂直滾動條一直顯示
//頭文件 #import <UIKit/UIKit.h> @interface TextView : UIView<UITextViewDelegate>{ UITextView *boxText; } //此方法可以不寫 - (id)initWithFrame:(CGRect)frame withContext:(NSString *)text; @end //實現文件 @implementation TextView /** @method UITextView自定義重寫封裝 @param frame 位置 @param text 視圖文本 */ /*此方法可以不實現 只在UITextView初始化的地方實現verticalScrollBar方法和 -(void)scrollViewDidEndDecelerating:(UIScrollView *)sc方法(其他的代理方法可以根據需要添加)*/ - (id)initWithFrame:(CGRect)frame withContext:(NSString *)text { self = [super initWithFrame:frame]; if (self) { boxText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; boxText.delegate = self; [boxText setText:text]; [boxText setTextColor:[UIColor whiteColor]]; [boxText setTextAlignment:UITextAlignmentLeft]; [boxText setBackgroundColor:[UIColor clearColor]]; [boxText setFont:[UIFont systemFontOfSize:15]]; [boxText setEditable:YES]; [self addSubview:boxText]; [boxText release]; [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(run) userInfo:nil repeats:NO]; } return self; } #pragma mark --視圖移動后判斷是否是UIImage,然后判斷是否是豎滾動條設置讓滾動條顯示-- -(void)verticalScrollBar{ [boxText setContentOffset:CGPointMake(0, 10) animated:NO]; for(UIView *img in [boxText subviews]){ if ([img isKindOfClass:[UIImageView class]] && img.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin){ [img setAlpha:1]; } } } #pragma mark --滾動視圖結束移動后判斷是否是UIImage,然后判斷是否是豎滾動條設置讓滾動條顯示-- -(void)scrollViewDidEndDecelerating:(UIScrollView *)sc{ for (UIView *img in [sc subviews]) { if ([img isKindOfClass:[UIImageView class]] && img.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin){ [img setAlpha:1]; } } } @end