swift - 如何将 NSTextField 值转换为 CGFloat
问题描述
let countY = CGFloat(self.textbox1.stringValue); //NSTextField value= 1024.231234
if let image:CGImage = CGDisplayCreateImage(CGMainDisplayID(), rect: CGRect(x: countX, y: countY, width: 1, height: 1))
{
我得到了错误
表达式类型“@lvalue String”在没有更多上下文的情况下不明确谢谢
解决方案
CGFloat
没有字符串初始值设定项。
只需doubleValue
从文本字段中获取,而不是stringValue
let countY = CGFloat(self.textbox1.doubleValue)
if let image = CGDisplayCreateImage(CGMainDisplayID(), rect: CGRect(x: countX, y: countY, width: 1, height: 1)) {
}
推荐阅读
- git - Jenkins git checkout 似乎比我要求的要多
- python - 用元组列表指定的另一个字符替换字符串中的数字
- java - 用于读取文件和存储对象的并发列表数据结构
- c - 如何使用 ID 查找进程的 RAM 使用情况?
- wordpress - Wordpress 从 get_post 返回不完整的 post_content
- tensorflow - 从 keras 使用 image_dataset_from_directory() 加载图像
- amazon-web-services - 检查与我的 IAM 角色关联的所有资源
- java - 如何使用有效的 JWT 解决 WebSecurityConfigurerAdapter 上的 403 错误?
- linux - 如何将 git 存储库共享给同一台机器上的特定用户?
- git - 从 git repo 中删除 .DS_Store