简体   繁体   English

如何在iPhone中将NSString转换为CGPoint

[英]How to Convert NSString into CGPoint in iPhone

我从UITextfield获取值到NSString,需要将NSString的值转换为CGPoint,假设如果我在文本字段中输入6,5它应该将其转换为CGPoint。

See CGPointFromString (documentation in link). 请参阅CGPointFromString (链接中的文档)。 The string has to be in the format {x,y} so you would need to add those to the user input yourself: 字符串必须采用{x,y}格式{x,y}因此您需要自己将这些添加到用户输入:

CGPoint myPoint = CGPointFromString([NSString stringWithFormat:@"{%@}",textField.text]);

Will return CGPointZero if the string is invalid. 如果字符串无效,将返回CGPointZero。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM