swift——uiwebview的使用
首先,创建一个label:
agreeDeal = UILabel()
let tap = UITapGestureRecognizer.init(target: self, action: #selector(LoginViewController.showPrivatePolicy))
agreeDeal.addGestureRecognizer(tap)
agreeDeal.userInteractionEnabled = true
//富文本,不同字体颜色大小和颜色
let labelString = NSLocalizedString("Login_agree deal", comment: "") as NSString
let rang = labelString.rangeOfString("《")
let firstRang = NSMakeRange(0, rang.location)
let secondRang = NSMakeRange(rang.location, labelString.length - rang.location)
let labelText = NSMutableAttributedString(string: labelString as String as String)
labelText.addAttributes([NSForegroundColorAttributeName:UIColor.init(white: 1, alpha: 0.8),NSFontAttributeName:UIFont.boldSystemFontOfSize(12)], range: firstRang)
labelText.addAttributes([NSForegroundColorAttributeName:UIColor.redColor(),NSFontAttributeName:UIFont.boldSystemFontOfSize(12)], range: secondRang)
agreeDeal.attributedText = labelText
agreeDeal.textAlignment = .Center
agreeDeal.numberOfLines = 0
bottomView.addSubview(agreeDeal)
agreeDeal.snp_makeConstraints { (make) in
make.centerX.equalTo(bottomView)
make.width.equalTo(kscreenWidth)
make.top.equalTo(facebookBtn.snp_bottom).offset(10)
make.height.equalTo(50)
}
跳到下一个web view的界面:
import UIKit
import MBProgressHUD
private let url = "http://www.coollang.com/appcontent/responsibility?type=6"
class PrivatePolicyController: UIViewController,NavigationBackProtocol {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
configureNav()
loadWeb()
}
func configureNav()
{
let titleStr = NSLocalizedString("Login_Privacy Policy", comment: "隐私政策")
title = titleStr
leftNavigationItem()
}
func loadWeb(){
let webUrl = NSURL(string: url)
let request = NSURLRequest.init(URL: webUrl!, cachePolicy: .UseProtocolCachePolicy, timeoutInterval:requestOverTime)
webView.loadRequest(request)
webView.delegate = self
}
}
extension PrivatePolicyController:UIWebViewDelegate
{
func webViewDidStartLoad(webView: UIWebView) {
MBProgressHUD.showHUDAddedTo(webView, animated: true)
}
func webViewDidFinishLoad(webView: UIWebView) {
MBProgressHUD.hideHUDForView(webView, animated: true)
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
MBProgressHUD.showTextWithMessageInBottom(error?.localizedDescription ?? "")
}
}
最新文章
- Spring.net 配置说明
- 分享我们项目中基于EF事务机制的架构
- 转载:C#中的泛型
- 怎么在Microsoft Project中冻结列
- pygal and matplotlib(again)
- Key-Value-Coding(KVC)
- PHP判断键值数组是否存在,使用empty或isset或array_key_exists
- 利用Jmeter做接口测试
- javassist动态修改class
- ARM启动流程
- poj 3154 Graveyard 贪心
- 广义后缀树(GST)算法的简介
- Java作业九(2017-11-6)
- Python脱产8期 Day13 2019/4/28
- ConcurrentHashMap源码
- 在 .NET 项目中集成 SwaggerUI(2018.9.30)
- Xutils简
- localStorage,sessionStorage的使用
- localStorage 不方便存储数组时的替代方法
- T-SQL 事务2