您的位置:首页 > 移动开发

[IOS]HTML格式的UIWebView展示

2014-09-11 15:59 162 查看
[IOS]HTML格式的UIWebView展示


#import "NVParentViewController.h"
@interface SZGameRules : NVParentViewController
@property (retain, nonatomic) IBOutlet UIWebView *gameRulesWV;//游戏规则WebViw
@property (retain, nonatomic) NSString           *gamerule;   //游戏规则HTML路径

//知道了
- (IBAction)knowThe:(id)sender;

@end

#import "SZGameRules.h"
@interface SZGameRules ()<UIScrollViewDelegate>
@end

@implementation SZGameRules

- (void)viewDidLoad
{
[super viewDidLoad];
//清空webView上面内容
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
[_infoWeb loadRequest:request];
[self cGameRules:_gamerule];
}
//HTML
-(void)cGameRules:(NSString *)gameRuleStr{
NSURL *url =[NSURL URLWithString:gameRuleStr];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[_gameRulesWV loadRequest:request];
[_gameRulesWV setFrame:CGRectMake(_gameRulesWV.frame.origin.x, _gameRulesWV.frame.origin.y, 244, 233)];
[_gameRulesWV setScalesPageToFit:YES];
//隐藏滚动条
_gameRulesWV.backgroundColor=[UIColor clearColor];
_gameRulesWV.opaque = NO;
//透明,=YES时默认为白色背景
for (UIView *aView in [_gameRulesWV subviews]){
[aView setBackgroundColor:[UIColor clearColor]];
if ([aView isKindOfClass:[UIScrollView class]]){
UIScrollView *tempSV = (UIScrollView *)aView;
tempSV.delegate = self;
tempSV.tag = 1321;
[tempSV setShowsHorizontalScrollIndicator:NO];
//滚动条不显示
[tempSV setShowsVerticalScrollIndicator:NO];
[tempSV setBounces:YES];
[tempSV setContentSize:CGSizeMake(1,tempSV.contentSize.height )];
for (UIView *shadowView in tempSV.subviews){
if ([shadowView isKindOfClass:[UIImageView class]]){
shadowView.hidden = YES;
//拖拽后的上下阴影
}
}
}
}
}

//知道了
- (IBAction)knowThe:(id)sender {
[self.view removeFromSuperview];
}

//避免UIWebView能左右拖动
#pragma mark UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView.tag == 1321){
CGPoint tempPoint = scrollView.contentOffset;
tempPoint.x = 0;
[scrollView setContentOffset:tempPoint];
}
}


 


图例:游戏规则

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: