objective c - Can't set image as the background of UILabel -


i have seen lots of questions in stackoverflow same issue, none of solutions helped me. have used following code set custom image background of label:

labelbackgroundimageoriginal = [uiimage imagenamed:@"paper.jpg"]; labelbackgroundimagesize = mylabel.frame.size;     uigraphicsbeginimagecontext(labelbackgroundimagesize); [labelbackgroundimageoriginal drawinrect:cgrectmake(0, 0, labelbackgroundimagesize.width, labelbackgroundimagesize.height)];     labelbackgroundimagenew = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); mylabel.backgroundcolor = [uicolor colorwithpatternimage:labelbackgroundimagenew]; 

but label background still white , image didn't show up. tried various solutions given under different questions following 1 one:

mylabel.backgroundcolor = [uicolor clearcolor]; mylabel.opaque = no; 

but none of them seem working well. there way out of this?

have try using [uicolor colorwithpatternimage:] directly image ? works fine me.

uilabel *test = [[uilabel alloc] initwithframe:cgrectmake(100, 100, 300, 100)]; test.text = @"test"; test.backgroundcolor = [uicolor colorwithpatternimage:[uiimage imagenamed:@"anypicture"]]; [self.view addsubview:test]; 

edit : i've tried code , works fine ! have checked if mylabel.frame.size value not null ?


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -