Programmatically setting a User Defined Runtime Attribute

Hatchmaster J

I added a User Defined Runtime Attribute to a UIButton using Interface Builder. The attribute is named strokeColor, and is of type Color.

I try to set it programmatically, as follows:

UIColor *someColor = [UIColor yellowColor];
[myButton setValue:someColor forKey:@"strokeColor"];

The second line crashes, and I get the following error:

'*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key strokeColor.'

What might be the cause of this exception? What data type does a user defined runtime attribute of type color expect?

memmons

Runtime attributes allow you to access properties of objects that would not otherwise be surfaced in Interface Builder, but you still have to define any properties you are accessing via a runtime attribute. Simply adding a runtime attribute to a class which doesn't have a matching property will throw an exception, as you have seen.

In your case, if you want to be able to set a property named strokeColor on a UIButton via a runtime attribute, first you must create a UIButton subclass or category that has the property, then you will be able to set it's corresponding runtime attribute;

Here's a UIButton category:

@interface UIButton (Coloring)

@property (nonatomic, strong) UIColor *strokeColor;

@end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting PetaPoco TableName Attribute at Runtime

From Dev

User Defined Runtime Attributes and Associated Objects

From Dev

Set "User Defined Runtime Attributes" in code

From Dev

UILabel extension, User defined runtime attributes

From Dev

Getting round Button With User Defined Runtime Attributes

From Dev

Getting round Button With User Defined Runtime Attributes

From Dev

How To Add User Defined Attribute in PIP Attribute User Store

From Dev

JMeter setting user defined variable in beanshell not working

From Dev

Python MySQLdb setting a user defined variable

From Dev

How to use User Defined Attribute in D language?

From Dev

User-defined methods and the __func__ attribute

From Dev

Terminology: A user-defined function object attribute?

From Dev

FactoryGirl::AttributeDefinitionError: Attribute already defined: user

From Dev

Getting user defined attribute values in angularjs

From Dev

How to use User Defined Attribute in D language?

From Dev

User-defined methods and the __func__ attribute

From Dev

Data extraction from user defined attribute

From Dev

Setting user programmatically in ASP.NET MVC5

From Dev

Programmatically setting the 'Connect as' user in IIS7 using C#

From Dev

Programmatically setting the 'Connect as' user in IIS7 using C#

From Dev

How do you retrieve User Defined Runtime Attributes in Xamarin?

From Dev

List of user defined runtime attributes available for an object in swift

From Dev

Rotate (angle) a UIView, using User Defined Runtime Attributes

From Dev

Is it possible to use User Defined Attributes to get values at runtime?

From Dev

User defined runtime attributes on iOS versions prior to 5.0

From Dev

Build Settings User-Defined Setting in GoogleService-info.plist

From Dev

Postgresql: variable length user-defined data type storage setting

From Dev

Java: How to put the value of a user defined attribute into an array?

From Dev

How to parse user defined html attributes using html DOM with '-' in that attribute?

Related Related

  1. 1

    Setting PetaPoco TableName Attribute at Runtime

  2. 2

    User Defined Runtime Attributes and Associated Objects

  3. 3

    Set "User Defined Runtime Attributes" in code

  4. 4

    UILabel extension, User defined runtime attributes

  5. 5

    Getting round Button With User Defined Runtime Attributes

  6. 6

    Getting round Button With User Defined Runtime Attributes

  7. 7

    How To Add User Defined Attribute in PIP Attribute User Store

  8. 8

    JMeter setting user defined variable in beanshell not working

  9. 9

    Python MySQLdb setting a user defined variable

  10. 10

    How to use User Defined Attribute in D language?

  11. 11

    User-defined methods and the __func__ attribute

  12. 12

    Terminology: A user-defined function object attribute?

  13. 13

    FactoryGirl::AttributeDefinitionError: Attribute already defined: user

  14. 14

    Getting user defined attribute values in angularjs

  15. 15

    How to use User Defined Attribute in D language?

  16. 16

    User-defined methods and the __func__ attribute

  17. 17

    Data extraction from user defined attribute

  18. 18

    Setting user programmatically in ASP.NET MVC5

  19. 19

    Programmatically setting the 'Connect as' user in IIS7 using C#

  20. 20

    Programmatically setting the 'Connect as' user in IIS7 using C#

  21. 21

    How do you retrieve User Defined Runtime Attributes in Xamarin?

  22. 22

    List of user defined runtime attributes available for an object in swift

  23. 23

    Rotate (angle) a UIView, using User Defined Runtime Attributes

  24. 24

    Is it possible to use User Defined Attributes to get values at runtime?

  25. 25

    User defined runtime attributes on iOS versions prior to 5.0

  26. 26

    Build Settings User-Defined Setting in GoogleService-info.plist

  27. 27

    Postgresql: variable length user-defined data type storage setting

  28. 28

    Java: How to put the value of a user defined attribute into an array?

  29. 29

    How to parse user defined html attributes using html DOM with '-' in that attribute?

HotTag

Archive