objective c - IOS drawing text inside a subview -


im trying draw text on subview, view appearing fine text not, im doing, view have black color, text have white color, text , rect value given in other method:

nsstring* sumtext = [[nsstring alloc]initwithformat:@"%0.1f",sum]; cgrect textrect = cgrectmake(chartlocation.x+chartlength+10,                               chartlocation.y,                               20,                               20); [self drawtextrect:sumtext inrect:textrect];   -(void)drawtextrect:(nsstring *)sumtext inrect:(cgrect)textrect { uifont* font=[uifont fontwithname:@"arial" size:(20/2)]; uicolor* textcolor = [uicolor whitecolor]; nsmutableparagraphstyle *paragraphstyle = [[nsparagraphstyle defaultparagraphstyle]mutablecopy]; paragraphstyle.alignment = nstextalignmentcenter; nsdictionary* stringattr=@{nsfontattributename:font,nsforegroundcolorattributename:textcolor,nsparagraphstyleattributename:paragraphstyle}; uiview* textview =[[uiview alloc] initwithframe:textrect]; textview.backgroundcolor = [uicolor blackcolor];  [sumtext drawinrect:textrect withattributes:stringattr]; [self.view addsubview:textview];} 

am wrong? thanks

there way can achieve want .

uilabel* lbltext = [[uilabel alloc]initwithframe:cgrectmake(50, 50, 200, 200)]; lbltext.text = @"hello world!"; lbltext.backgroundcolor = [uicolor blackcolor]; lbltext.textcolor = [uicolor whitecolor]; [self.view addsubview:lbltext]; 

and output is:

output


Popular posts from this blog