http://www.cocoachina.com/bbs/simple/?t64154.html
//头文件
#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 视图文本
*/
- (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)run{
[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];
}
}
}
#pragma mark --禁止UITextView的选择和编辑--
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}
@end