1、iOS 开发textView不能从顶部显示:
textView.contentInset = UIEdgeInsets(top: -8, left: 0, bottom: -10, right: 0)
2.WKWebView清除缓存:
func ClearCache() {
let dateFrom: NSDate = NSDate.init(timeIntervalSince1970: 0)
if #available(iOS 9.0, *) {
let websiteDataTypes: NSSet = WKWebsiteDataStore.allWebsiteDataTypes() as NSSet
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes as! Set<String>, modifiedSince: dateFrom as Date) {
print("清空缓存完成")
}
} else {
let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let cookiesFolderPath = libraryPath.appendingFormat("/Cookies")
try? FileManager.default.removeItem(atPath: cookiesFolderPath)
}
}
3.webView设置缓存策略:
let urlRequest = URLRequest.init(url: URL.init(string: urlStr!)!, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData)
case useProtocolCachePolicy//默认方式
case reloadIgnoringLocalCacheData//不使用缓存
case reloadIgnoringLocalAndRemoteCacheData//决不使用任何缓存
case returnCacheDataElseLoad//使用缓存(不管它是否过期),如果缓存中没有,那从网络加载吧
case returnCacheDataDontLoad//离线模式:使用缓存(不管它是否过期),但是不从网络加载
case reloadRevalidatingCacheData//验证本地数据与远程数据是否相同,如果不同则下载远程数据,否则使用本地数据
4.Cocopods和Cathage是否可以一起使用:
本人验证是可以的哟!
1>
cd
touch Podfile
platform :ios, '9.0'
target 'Test' do
use_frameworks!
pod 'DoraemonKit/Core', '~> 1.1.4', :configurations => ['Debug']
pod 'DoraemonKit/WithLogger', '~> 1.1.4', :configurations => ['Debug']
end
pod install
2>
cd
touch Cartfile
github "SnapKit/SnapKit"
Carthage update --platform iOS
项目使用.xcworkspace打开运行即可啦。
5.检查网络状态:
if !NetworkReachabilityManager()!.isReachable {
HUDManager.showAutoDismissFailedMessage("请检查网络情况")
return
}
6.Swift加载Gif:
pod 'SwiftGifOrigin', '~> 1.7.0'
https://github.com/swiftgif/SwiftGif
7.UIImageView简单动画:
//创建UIImageView
let imgV=UIImageView(frame: CGRectMake(20, 100, 100, 100))
imgV.animationDuration=2.0
imgV.tag=99
//创建图片
var images=[UIImage]()
for i in 0...2{
let img=UIImage(named: "test\(i)")
images.append(img!)
}
//设置UIImageView的image
imgV.animationImages=images
//以上方法中设置了animationImages 我们会发现当停止动画的时候imgV上边直接没有图片了,如果需要点停止动画之后还能现实图片。我们需要设置图片
imgV.image=UIImage(named: "test2.png")
//设置循环次数,0无限循环
imgV.animationRepeatCount=0
imgV.startAnimating()
self.view.addSubview(imgV)