如何在iPhone中将NSString转换为CGPoint [英] How to Convert NSString into CGPoint in iPhone
本文介绍了如何在iPhone中将NSString转换为CGPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从UITextfield获取值到NSString,需要将NSString的值转换为CGPoint,假设如果我在文本字段中输入6,5它应该将其转换为CGPoint。
I am getting the values from UITextfield into NSString , need to convert the values of NSString into CGPoint, Suppose if i enter 6,5 into textfield it should covert it into CGPoint.
推荐答案
参见 CGPointFromString (链接中的文档)。该字符串必须采用 {x,y}
格式,因此您需要自己将这些添加到用户输入中:
See CGPointFromString (documentation in link). The string has to be in the format {x,y}
so you would need to add those to the user input yourself:
CGPoint myPoint = CGPointFromString([NSString stringWithFormat:@"{%@}",textField.text]);
如果字符串无效,将返回CGPointZero。
Will return CGPointZero if the string is invalid.
这篇关于如何在iPhone中将NSString转换为CGPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文