Search code examples
iosobjective-ciphoneios7

IOS UIConstant declaration and calling


I have created a Constant.h file that contains following code

#ifndef myapp_Constants_h
#define myapp_Constants_h

#define cancel_bt @"cancel.png"

#endif

How can I call cancel_btn image as button image


Solution

  • All the #define does for you is to create a macro that gets replaced at compile time.

    If you #import your Constant.h file at the top of a second file, any time the string occurs in that second file, the preprocessor will replace it with the string @"cancel.png".

    So if you add code that loads a image into a button, you could use cancel_bt as an image name instead of @"cancel.png"

    From your question it sounds like you don't know how to replace a button's image through code. You want to use the UIButton method setImage:forState:. See the docs for more info on using it.