一.最近写项目发现接手的项目里面警告有900多条,大概看了一下全是三方库报的警告,当时就没太在意。然后这几天写项目的时候,每当有编辑错误的时候,就要跨过茫茫的三方库的警告去找自己的bug。在今天终于忍不住了,就想要解决了他们,就发现我们可以在podfile文件中 增加一句 inhibit_all_warnings! 来要pod的工程不显示任何警告
这样就不会再提示由第三方问题而显示的警告了
二.富文本在我们开发中是不可缺少的使用方法,可以对label文本的显示进行各种风格设置。而且富文本的使用方法也很多,绝对值得每个开发者认真总结一下其用法。
最常用的就是这种直接定义的
NSMutableAttributedString * attString = [[NSMutableAttributedString alloc]initWithString:string attributes:@{NSForegroundColorAttributeName:hexColor(@"4382FD"),NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:12.0]}];
然后当我们需要添加其他的文本设置,我们可以使用addAttribute方法
[attString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFangSC-Semibold" size:12.0] range:range];
以下附上富文本的属性名称
NSFontAttributeName 字体 NSParagraphStyleAttributeName 段落格式 NSForegroundColorAttributeName 字体颜色 NSBackgroundColorAttributeName 背景颜色NSStrikethroughStyleAttributeName 删除线格式 NSUnderlineStyleAttributeName 下划线格式NSStrokeColorAttributeName 删除线颜色 NSStrokeWidthAttributeName 删除线宽度NSShadowAttributeName 阴影
三.在项目使用webview的时候,为了显示加载可以添加一个进度条显示
(1)为页面添加UIProgressView属性
@property (nonatomic, strong) UIProgressView *progressView;//设置加载进度条
(2)懒加载UIProgressView
-(UIProgressView *)progressView{
if (!_progressView) {
_progressView = [[UIProgressView alloc]
initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.frame = CGRectMake(0, 64, screen_width, 5);
[_progressView setTrackTintColor:[UIColor colorWithRed:240.0/255
green:240.0/255
blue:240.0/255
alpha:1.0]];
_progressView.progressTintColor = [UIColor greenColor];
}
return _progressView;
}
(3)在初始化WKWebView时(我是在懒加载时) kvo 添加监控
[_mywebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))
options:0 context:nil];
(4)页面开始加载时,隐藏进度条
//开始加载-(void)webView:(WKWebView *)webView
didStartProvisionalNavigation:(WKNavigation *)navigation{
//开始加载的时候,让进度条显示 self.progressView.hidden = NO;
}
(5)kvo 监听进度
//kvo 监听进度-(void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))]
&& object == self.mywebView) {
[self.progressView setAlpha:1.0f];
BOOL animated = self.mywebView.estimatedProgress > self.progressView.progress;
[self.progressView setProgress:self.mywebView.estimatedProgress animated:animated];
if (self.mywebView.estimatedProgress >= 1.0f) {
[UIView animateWithDuration:0.3f
delay:0.3f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.progressView setAlpha:0.0f];
}
completion:^(BOOL finished) {
[self.progressView setProgress:0.0f animated:NO];
}];
}
}else{
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
}
}
(6)在dealloc方法里移除监听
-(void)dealloc{
[self.mywebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];
}
网友评论