如何将类型的值转换'[String : AnyObject]?'为预期的参数类型'[NSAttributedStringKey : Any]?'?
open class func drawText(context: CGContext, text: String, point: CGPoint,
align: NSTextAlignment, attributes: [String : AnyObject]?)
{
var point = point
if align == .center
{
point.x -= text.size(withAttributes: attributes).width / 2.0
}
else if align == .right
{
point.x -= text.size(withAttributes: attributes).width
}
NSUIGraphicsPushContext(context)
(text as NSString).draw(at: point, withAttributes: attributes)
NSUIGraphicsPopContext()
}
Run Code Online (Sandbox Code Playgroud) 我是iOS开发的新手.我想从父视图中切换(隐藏/可见)子视图.在android中有一种隐藏可见性的方法.
在android中
subView.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
在iOS中
subView.removeFromSuperview()
Run Code Online (Sandbox Code Playgroud)
当我使用上面的函数它删除subViewConstraints并弄乱我的滚动视图约束.
topsubView.bottomAnchor.constraint(equalTo: bottomSubView.topAnchor, constant: 8).isActive = true
Run Code Online (Sandbox Code Playgroud)
当我使用上面的代码它工作正常并隐藏subView.but当我想使subView可见时,它不显示subView.
topsubView.bottomAnchor.constraint(equalTo: bottomSubView.topAnchor, constant: 8).isActive = false
self.view.layoutIfNeeded()
Run Code Online (Sandbox Code Playgroud)
希望你能理解我的问题.谢谢你提前.
我想我的iOS App的主模块编译Swift 4.0,而CocoaPods模块编译swift 3.
PS:使用Xcode 9 beta 2.
我正在使用iOS 11的大标题导航栏,但是当我添加一个条形按钮项时,它看起来很奇怪,位于与原始标题导航栏相同的位置.我想在标题很大时向下移动条形按钮项目,并在导航栏不再大时将其移回原始位置.这样做的最佳方式是什么?
这是显示条形按钮项目的奇怪位置的图像
我可以使用viewWillLayoutSubviews()动态获取导航栏高度,但我无法使用setTitlePositionAdjustment更改条形按钮项的位置
override func viewWillLayoutSubviews() {
guard let navbarHeight = self.navigationController?.navigationBar.frame.height else{ return }
}
Run Code Online (Sandbox Code Playgroud) 我试图在我的一个UIViewControllers(Swift 4)中隐藏状态栏.
首先,我设置基于控制器的视图状态栏的外观到是在Info.plist.
我prefersStatusBarHidden在我的控制器中覆盖了该属性:
override var prefersStatusBarHidden: Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
viewDidLoad(),我添加setNeedsStatusBarAppearanceUpdate()了强制prefersStatusBarHidden读取属性的函数.毕竟,我仍然看到状态栏UIViewController.
有谁可以帮助我吗?
我有以下代码.
import Foundation
let jsonData = """
[
{"firstname": "Tom", "lastname": "Smith", "age": "28"},
{"firstname": "Bob", "lastname": "Smith"}
]
""".data(using: .utf8)!
struct Person: Codable {
let firstName, lastName: String
let age: String?
enum CodingKeys : String, CodingKey {
case firstName = "firstname"
case lastName = "lastname"
case age
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
firstName = try values.decode(String.self, forKey: .firstName)
lastName = try values.decode(String.self, forKey: .lastName)
age = try values.decode(String.self, forKey: .age) …Run Code Online (Sandbox Code Playgroud) 我使用webview加载url但是没有加载.
我尝试过与wkwebview相同但无法加载网址.
我做了以下
日志:
dnssd_clientstub ConnectToServer:connect() - >尝试次数:1
dnssd_clientstub ConnectToServer:connect() - >尝试次数:2
dnssd_clientstub ConnectToServer:connect() - >尝试次数:3 dnssd_clientstub ConnectToServer:connect()失败路径:/ var/run/mDNSResponder套接字:11错误:-1错误:1不允许操作
nw_resolver_create_dns_service_locked DNSServiceCreateConnection失败:ServiceNotRunning(-65563)
-码
@IBOutlet weak var webvw: WebView!
override func viewDidAppear() {
super.viewDidAppear()
guard let url = URL(string: "https://www.google.co.in") else { return }
let request = URLRequest(url: url)
webvw.uiDelegate = self
webvw.frameLoadDelegate = self
webvw.mainFrame.load(request)
}
Run Code Online (Sandbox Code Playgroud) 我需要为我的要求制作swift静态库.我制作了swift静态库,它使用swift和Obj-c代码.我通过桥文件包含了Obj-c文件.我能够编译swift静态库而不会出现任何错误,并获取libMySwift.a文件.我使用Xcode9.3和Swift4来编译库.
我在obj-c项目中包含了libMySwift.a,还包含了obj-c兼容的头文件来访问项目中的lib.当我尝试编译项目时,它会给出以下警告和200多个错误.
Auto-Linking library not found for -lswiftSwiftOnoneSupport
Auto-Linking library not found for -lswiftCore
Auto-Linking library not found for -lswiftQuartzCore
Auto-Linking library not found for -lswiftCoreImage
Auto-Linking library not found for -lswiftCoreGraphics
Auto-Linking library not found for -lswiftObjectiveC
Auto-Linking library not found for -lswiftDispatch
Auto-Linking library not found for -lswiftMetal
Auto-Linking library not found for -lswiftFoundation
Auto-Linking library not found for -lswiftUIKit
Auto-Linking library not found for -lswiftDarwin
Auto-Linking library not found for -lswiftCoreFoundation
Run Code Online (Sandbox Code Playgroud)
如果我遗漏任何步骤或需要添加任何内容,请告诉我.
更新到Swift 4后,我收到编译器错误:
Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol'
这是我的viewWillAppear自定义Tab Bar Controller子类中的方法,我正在设置项目文本的字体.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// compiler error on line below
UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal)
}
Run Code Online (Sandbox Code Playgroud)
我无法解决这个问题,任何指导都将不胜感激,谢谢!
我在将Swift 3代码转换为Swift 4时遇到了麻烦.我已成功地将应用程序中的所有其他内容成功翻译,但是我遇到了一行代码问题:
cleanURL = cleanURL.substring(to: cleanURL.index(before: cleanURL.endIndex))
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
ViewController.swift:62:33: 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
Run Code Online (Sandbox Code Playgroud) swift4 ×10
ios ×7
swift ×7
swift3 ×2
xcode9-beta ×2
cocoapods ×1
codable ×1
ios11 ×1
macos-sierra ×1
uiappearance ×1
view ×1
webview ×1
xcode9 ×1
xcode9.3 ×1