解决有的图片显示时只是一块颜色,而显示不正常的问题
//渲染UIImage*image = [UIImageimageNamed:@"imageName"];image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
毛玻璃效果
UIImageView*imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"xiaoxin3"]];//毛玻璃效果UIVisualEffectView*visualView = [[UIVisualEffectViewalloc]initWithEffect:[UIBlurEffecteffectWithStyle:(UIBlurEffectStyleLight)]];visualView.frame=self.tableView.bounds;visualView.alpha=0.8;[imageView addSubview:visualView];self.tableView.backgroundView= imageView;
视图截圆角
_customView.layer.masksToBounds = YES;_customView.layer.cornerRadius = self.customView.bounds.size.width/2;
使用NSURLSession请求网络数据
//通过单例创建Session对象//步骤1.NSURLSession 服务器数据异步加载,作用和NSURLConnection的作用相同NSURLSession*session = [NSURLSessionsharedSession];//步骤2.封装网络请求NSURLRequest*request = [[NSURLRequestalloc] initWithURL:[NSURLURLWithString:@"baidu.com"]];//步骤3.准备加载数据,创建这个任务的taskNSURLSessionTask*task = [session dataTaskWithRequest:request completionHandler:^(NSData* _Nullable data,NSURLResponse* _Nullable response,NSError* _Nullable error) {//当加载数据完成时,调用该blockNSLog(@"%@",data);//手动解析网络数据NSDictionary*dict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];NSLog(@"%@",data);}];//调用此方法开始加载数据[task resume];
播放语音
//导入包import //声音集成器AVSpeechSynthesizer*speechSy = [[AVSpeechSynthesizeralloc] init];//发声器AVSpeechUtterance*utterance = [[AVSpeechUtterancealloc] initWithString:@"i am very happy"];AVSpeechUtterance*utterance2 = [[AVSpeechUtterancealloc] initWithString:@"ha ha ha"];AVSpeechUtterance*utterance3 = [[AVSpeechUtterancealloc] initWithString:_textFeild.text];//给合成器添加发生器,让其发音[speechSy speakUtterance:utterance];[speechSy speakUtterance:utterance2];[speechSy speakUtterance:utterance3];//哪国语言utterance.voice= [AVSpeechSynthesisVoicevoiceWithLanguage:@"en-US"];//语速utterance.rate=0.5;//音高utterance.pitchMultiplier=1.0;
webView
UIWebView*webView = [[UIWebViewalloc] initWithFrame:self.view.frame];[webView loadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:myurl]]];self.view= webView;
使用第三方SDWevImage解析图片
[cell.imgViewsd_setImageWithURL:[NSURLURLWithString:news.picUrl]placeholderImage:[UIImageimageNamed:@"image"]];
设置cell的自适应高度
使用此方法必须要设置cell中的最后一个控件与cell的距离
self.myTableView.rowHeight=UITableViewAutomaticDimension;self.myTableView.estimatedRowHeight=100;
让音乐在后台播放
[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];
将URL中的汉字转换成utf-8格式,拼接到URL字符串中
NSString*typeString = (__bridgeNSString*)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridgeCFStringRef)@"健康",NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
去除解析出来的数据带的 HTML 标记
- (NSString *)filterHTML:(NSString *)html{NSScanner * scanner = [NSScannerscannerWithString:html];NSString * text = nil;while([scanner isAtEnd]==NO){//找到标签的起始位置[scannerscanUpToString:@"<"intoString:nil];//找到标签的结束位置[scannerscanUpToString:@">"intoString:&text];//替换字符html = [htmlstringByReplacingOccurrencesOfString:[NSStringstringWithFormat:@"%@>",text]withString:@""];}returnhtml;}
去广告
先到网页,找到开发者平台,依次输入并提交
document.getElementsByClassName(‘index_mask’) ->
document.getElementsByClassName(‘index_mask’)[0] ->
document.getElementsByClassName(‘index_mask’[0].style.display = ‘none’
若在网页上显示的对应的广告没了,就可以将最后一句写到下面的程序中
-(void)webViewDidFinishLoad:(UIWebView *)webView{[webViewstringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('index_mask')[0].style.display = 'none'"];}
图片自适应
imgView.contentMode = UIViewContentModeScaleAspectFit;
解决tableView的head不会和cell一起滚动的问题
self.tableView= [[UITableViewalloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];
解决有navigationbar的情况下,下面的tableView与navigationbar有一段距离的问题
self.automaticallyAdjustsScrollViewInsets=NO;
数据再cell中解析,给cell做自适应高度时,无法实现
可能是因为cell出现时,自适应高度已经实现了,但是还没有内容,所以想办法先刷新一下数据(使用block块可以在cellForRow……方法中实现)