设置UITextView的垂直滚动条一直显示

 

 

设置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  

 

posted @ 2016-12-26 10:39  #零下一度&  阅读(1929)  评论(0编辑  收藏  举报