ios - Displaying image in UIButton -
to preface question, extremely new objective-c , xcode. have been learning week or have been stuck on problem few days. trying display image in uibutton. have 3 choose from, blue.png, purple.png , orange.png. no matter or image tell xcode use, display blue image. have deleted image project entirely. have "reset content , settings" in ios simulator. going on here?
the.h code
iboutlet uibutton *h1;
the.m code
uiimage *buttonimage = [uiimage imagenamed:@"purple.png"]; [h1 setimage:buttonimage forstate:uicontrolstatenormal]; [self.view addsubview:h1];
no matter image specify within quotes, uses blue.png, when image no longer exists in project. everybody!
you must have set blue.png
background image in storyboard or xib file. write nslog(@"%@",buttonimage) make sure image not nil. make sure entering correct name , extension purple.png
and also, use
[h1 setbackgroundimage:buttonimage forstate:uicontrolstatenormal];
instead of setimage
Comments
Post a Comment