-1

I made a custom UITextField with an additional user defined runtime attribute validRange, which I can set in the storyboard view. I use this property to check in the EndEditing method to validate the new set text. I works all fine, till I had to set a valid range from {-100,100} As NSRange uses NSUInteger, there are no minus values possible.

What is the best way to still make this happen? Would it be acceptable if I use CGSize instead of NSRange?

Updated Content Xcode only gives me the following choice of data types for the user defined runtime attributes:

enter image description here

This means I cannot define a new struct to create a CustomRange with NSInteger. As Point,Size are both {NSInteger,NSInteger} data types, I thought about using them. But this would be certainly a misuse, so I am wondering if someone knows a better solution, as misusing Point or Size to get this to work.

As another workaround I could user String, which I manually would split up in a method of the custom UITextField, but then there is no type safety.

4

1 回答 1

0

然后,我建议您定义两个具有合适名称的 NSNumber 属性来表示 NSRange 值,而不是滥用 CGSize,因为使用 CGSize 会混淆其他读者/程序员,因为我们有句话说,我们为他人而不是为自己编码。

还有一个NSNumber类方法如下

+ (NSNumber *)numberWithInteger:(NSInteger)value

它允许您按照您的意图包装有符号整数值。

于 2014-11-16T00:14:19.523 回答