如何将 NSTextField 值转换为 CGFloat
How to convert NSTextField value to 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))
{
我得到了错误
Expression type '@lvalue String' is ambiguous without more context
Thanks
CGFloat
没有字符串初始值设定项。
只需从文本字段中获取 doubleValue
而不是 stringValue
let countY = CGFloat(self.textbox1.doubleValue)
if let image = CGDisplayCreateImage(CGMainDisplayID(), rect: CGRect(x: countX, y: countY, width: 1, height: 1)) {
}
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))
{
我得到了错误
Expression type '@lvalue String' is ambiguous without more context Thanks
CGFloat
没有字符串初始值设定项。
只需从文本字段中获取 doubleValue
而不是 stringValue
let countY = CGFloat(self.textbox1.doubleValue)
if let image = CGDisplayCreateImage(CGMainDisplayID(), rect: CGRect(x: countX, y: countY, width: 1, height: 1)) {
}