How does one set the image of a UIButton from within the code?
I try the following but it just leaves the button as a white square.
[A1 setImage:[UIImage imageNamed:[NSString stringWithFormat:@"m1.10001.png"]] forState:UIControlStateNormal];
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your image construction seems a bit overly complicated, but it should work. Don’t forget to use the correct button type (custom):
With newer SDKs you can omit the .png. Make sure that the image actually exists (you can store it in a temporary variable and check for
nil, for example).And of course make sure that the button exists (or is bound), i.e. non-nil, when setting the image.