#import "wangmumu.h"
#import <WebKit/WebKit.h>
@interface wangmumu ()
@property (nonatomic, strong) WKWebView *htmlWebView;
@property (nonatomic, strong) UIProgressView *progressView;
@end
@implementation wangmumu
- (void)viewDidLoad {
[super viewDidLoad];
if ([self.isPop isEqualToString:@"pop"]) {
[self setNavigationBarWhiteColor];
} else {
[self creatBack];
}
}
- (void)createUI {
[self.view addSubviewS:self.htmlWebView,self.progressView,nil];
[self.htmlWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)updateView {
kWeakSelf(self)
[self.htmlWebView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.equalTo(weakself.view);
}];
}
- (void)creatBack {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Backicon"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"Backicon"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"Backicon"] forState:UIControlStateSelected];
button.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
button.frame = (CGRect){{0,0},{40,40}};
[[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
}
#pragma mark - KVC and KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([@"estimatedProgress" isEqualToString:keyPath]) {
[self.progressView setProgress:self.htmlWebView.estimatedProgress animated:YES];
}
if (self.progressView.progress == 0) {
self.progressView.hidden = NO;
} else if (self.progressView.progress == 1) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.progressView.progress ==1) {
self.progressView.progress = 0;
self.progressView.hidden = YES;
}
});
}
}
#pragma mark --- 实例化
- (WKWebView *)htmlWebView {
if (_htmlWebView == nil) {
_htmlWebView = [[WKWebView alloc] init];
NSURLRequest *requestUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:self.getUrl]];
[_htmlWebView loadRequest:requestUrl];
}
return _htmlWebView;
}
-(UIProgressView *)progressView {
if (_progressView == nil) {
CGRect rect = CGRectZero;
rect.size.width = [[UIScreen mainScreen]bounds].size.width;
rect.size.height = 2;
_progressView = [[UIProgressView alloc]initWithFrame:rect];
_progressView.progressTintColor = [UIColor hexColor:@"#FFC400"];
[_progressView setProgressViewStyle:UIProgressViewStyleDefault];
[self.view addSubview:_progressView];
}
return _progressView;
}
- (void)dealloc {
[self.htmlWebView removeObserver:self forKeyPath:@"estimatedProgress"];
self.htmlWebView = nil;
[self.htmlWebView removeFromSuperview];
}
@end
WKWebView 进度条设置
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1NSTimer+addition.h #import @interface NSTimer (addition)...
- 1.绘制20个方形组合的进度条 根据定点坐标和画笔属性绘制 根据进度大小来区别画笔颜色,用于显示当前声音进度 当前...
- Xamarin XAML语言教程使用Progress属性数据绑定设置进度条进度 开发者除了可以为ProgressB...
- Xamarin XAML语言教程使用属性设置进度条的当前进度 在图12.19~12.21中我们看到的是没有实现加载...