我在我的 macOS 应用程序的设置面板中使用 NSGridView。我是这样设置的:
class GeneralViewController: RootViewController {
private var gridView: NSGridView?
override func loadView() {
super.loadView()
let restaurantLabel = NSTextField()
restaurantLabel.stringValue = "Restaurant"
let restaurantButton = NSPopUpButton()
restaurantButton.addItems(withTitles: ["A", "B", "C"])
let updatesLabel = NSTextField()
updatesLabel.stringValue = "Updates"
updatesLabel.isEditable = false
updatesLabel.isBordered = false
updatesLabel.isBezeled = false
let updatesButton = NSButton(checkboxWithTitle: "Automatically pull in updates from WordPress", target: nil, action: nil)
let empty = NSGridCell.emptyContentView
gridView = NSGridView(views: [
[restaurantLabel, restaurantButton],
[updatesLabel, updatesButton]
])
gridView?.wantsLayer = true
gridView?.layer?.backgroundColor = NSColor.red.cgColor
gridView?.column(at: 0).xPlacement = .trailing
gridView?.rowAlignment = .firstBaseline
gridView?.setContentHuggingPriority(NSLayoutConstraint.Priority(rawValue: 600), for: .horizontal)
gridView?.setContentHuggingPriority(NSLayoutConstraint.Priority(rawValue: 600), for: .vertical)
view.addSubview(gridView!)
}
override func viewDidLayout() {
super.viewDidLayout()
gridView?.frame = NSRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
}
}
现在,当我运行它时,NSGridView 填满了整个 View ,但复选框确实关闭了。正如你在图片中看到的那样。
此外,我希望内容不会填满整个单元格,让所有内容看起来更居中。
我该如何解决这个问题?
最佳答案
如果将行对齐更改为 .lastBaseline,它将解决 NSButton 和 NSTextField 的垂直对齐问题。如果你想要更多的间距(我猜这就是你的意思“我希望内容不会填满整个单元格”),你可以使用 columnSpacing 和 rowSpacing NSGridView 的属性。如果您随后还在“真实”内容周围添加 NSGridCell.emptyContentView 实例,您应该能够实现以下效果。
这是我建议的更改后的新代码:
class GeneralViewController: RootViewController {
private var gridView: NSGridView?
override func loadView() {
super.loadView()
let restaurantLabel = NSTextField()
restaurantLabel.stringValue = "Restaurant"
let restaurantButton = NSPopUpButton()
restaurantButton.addItems(withTitles: ["A", "B", "C"])
let updatesLabel = NSTextField()
updatesLabel.stringValue = "Updates"
updatesLabel.isEditable = false
updatesLabel.isBordered = false
updatesLabel.isBezeled = false
let updatesButton = NSButton(checkboxWithTitle: "Automatically pull in updates from WordPress", target: nil, action: nil)
let empty = NSGridCell.emptyContentView
gridView = NSGridView(views: [
[empty],
[empty, restaurantLabel, restaurantButton, empty],
[empty, updatesLabel, updatesButton, empty],
[empty],
[empty]
])
gridView?.wantsLayer = true
gridView?.layer?.backgroundColor = NSColor.red.cgColor
gridView?.column(at: 0).xPlacement = .trailing
gridView?.rowAlignment = .lastBaseline
gridView?.columnSpacing = 20
gridView?.rowSpacing = 20
gridView?.setContentHuggingPriority(NSLayoutConstraint.Priority(rawValue: 600), for: .horizontal)
gridView?.setContentHuggingPriority(NSLayoutConstraint.Priority(rawValue: 600), for: .vertical)
view.addSubview(gridView!)
}
override func viewDidLayout() {
super.viewDidLayout()
gridView?.frame = NSRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
}
}
关于swift - NSGridView 困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52045470/
它似乎在寻找libmagic.so.1文件。我有那个文件。它位于/usr/lib64。我没有以root用户身份运行此安装。我也在使用rvm和Bundler。这是我的“bundle”命令的结果,当它到达我的Gemfile中的ruby-filemagic行时:[server@mineext]$rubyextconf.rb--with-magiclibcheckingformagic_open()in-ltrue...no***ERROR:missingrequiredlibrarytocompilethismodule***extconf.rbfailed***Couldnotcrea
或者更确切地说,为什么没有更好的工具来分析ruby中的内存,特别是Rails应用程序?最近,我们的Rails应用程序(托管在heroku上)开始在workerdynos中发现大量R14错误。这意味着我们的内存不足。将测功机提高到2倍(512mb->1GB)只能暂时缓解问题,让我相信某处存在内存泄漏。自然地,我的下一步是找到一个可以帮助我发现泄漏源的良好分析工具。也许我只是不知道可用的工具,或者我只是不知道如何使用我拥有的工具。我的愿望是我可以安装一个gem,然后运行关于内存使用统计的报告。由于我的内存问题与运行延迟作业的workerdynos隔离,因此点击端点获取报告并不可行。我看
是否有方法可以防止或使某人难以注入(inject)Javascript并操纵变量或访问函数?我有一个想法是在每次重新加载时随机更改所有var名称,以便每次都需要重写恶意软件脚本?或者还有其他不那么痛苦的方法吗?我知道最终有人会闯入,但我想知道如何使重现操作变得困难,这样人们就不会发布小书签或类似的东西供所有人使用。我不在乎专家是否在代码中找到了他们的方法,但我希望它比javascript:d=0;复杂一点如果您知道如何让破解Javascript变得更加困难,请写下来。 最佳答案 接受您的javascript将被“操纵”并在服务器端进
我是围棋的初学者。而我刚刚安装了gophernotes,打算主要使用JupyterNotebook进行编程。此程序在Jupyter中运行时出现以下错误:Cell1:packagemainOut1:runtimeerror:indexoutofrangeCell2:import"fmt"funcmain(){fmt.Println("helloworld")}main()Out2:helloworld当我在test.go中编写相同的内容并从bash执行时:goruntest.go,我得到以下信息:Deepaks-MacBook-Air:JUPYTERdeepak$goruntest.go
当我将time.Now()编码到JSON对象时,它给出的结果为"2009-11-10T23:00:00Z"但打印时间。现在给出2009-11-1023:00:00+0000UTC。他们为什么不同。什么是T和Z。另外,如何根据this将其转换为swiftNSDate对象?表? 最佳答案 这些值的含义无关紧要,它们是该格式(ISO8601)的一部分。有几种方法可以解决这个问题。一种是为时间或您的结构定义自定义MarshalJSON()方法并使用它来格式化日期,另一种是首先在您的结构中将其表示为字符串,以便当默认实现执行你得到你正在寻找的
这个问题在这里已经有了答案:StuckonGoogleHomeTutorial(1个回答)关闭5年前。我卡在了这个教程上。每次我导航到我的文件所在的位置并尝试“gorunpopulationapi.go”步骤时,都没有任何反应。我在我的工作区中创建了一个文件populationapi.go,我已经将其设置为GOPATH变量。我有一台Windows电脑。它应该位于三个文件夹中的哪一个(bin、pkg或src)?关于出了什么问题有什么想法吗?https://www.programmableweb.com/news/how-to-get-started-google-actions/how-
在C/C++/Java/Go中,我们使用,来分隔参数:(aint,bint)在ObjectiveC中,我们使用:来表示参数::(int)a:(int)b在Swift中,我们必须同时使用:和,:(a:int,b:int)是否需要冗余? 最佳答案 Swift可能有外部和内部参数名称:(externalinternal:Int)如果没有独特的分隔符,会产生很多歧义。 关于objective-c-为什么Swift函数定义语法是多余的?,我们在StackOverflow上找到一个类似的问题:
我的Swift应用程序与用Go编写的服务器通信。我希望使用Zlib压缩传输的数据,但压缩结果似乎与Swift和Go不同。这是Go版本:sourceString:="A-t-ellebesoind'autrespreuves?Acceptez-lapourleplaisir.J'aitantfaitquedelacueillir,Etc'estpresqueunefleur-des-veuves."//Compressionvarbbytes.Bufferwriter:=zlib.NewWriter(&b)writer.Write([]byte(sourceString))writer.
我正在使用rsaEncryptionOAEPSHA256AESGCM在iOS上使用SecKeyCreateEncryptedData加密一些数据,然后在golang后端解密相同的数据。我正在使用3072位rsa公钥来加密对称key。当我从iOS获取数据到后端时,我能够成功解密对称key,但gcm标签验证失败。我使用的是与iOS相同的16字节IV,但不知道iOS在加密时是否使用任何aad(附加身份验证数据)。有谁知道rsaEncryptionOAEPSHA256AESGCMforiOS是否使用了一些aad?这适用于iOS10+。我已经尝试过使用nil、空的16字节数组、aeskey本身、
我试图使用xmlSerializer制作一个xml文件。这将从用户界面、用户名和密码中获取2个值。因此,每个条目都将附加到xml文件中。如果我使用下面的代码,它只会保留最后一个条目-FileOutputStreamfileos=getApplicationContext().openFileOutput(xmlFile,Context.MODE_PRIVATE);同样,如果我使用MODE_APPEND而不是private,那么它会获取所有给定的xml标记-likeversion等等。FileOutputStreamfileos=getApplicationContext().openF