ios uitextfield to get text and manage label and image how to manage this -
i want make speech bubble app , if have demo link please share me ,here share image please me have 1 text field , textfield text set in label dynamic height , image set dynamic height width here share image link please check link image screenshot have facing lost of problem here code
here code
-(void)textheight { nsstring *message = txtmain.text; cgsize size = [message sizewithfont:[uifont fontwithname:fontname size:fontsize] constrainedtosize:cgsizemake(lbltextinbubbles.frame.size.width, 9999.0f) linebreakmode:nslinebreakbycharwrapping]; cgfloat height = size.height+60; cgfloat width = size.width+50; // nslog(@"w== %f,, h==%f",width,height); if(lblpositionwidth < 210) { if(lblpositiondynamicchange > 33) { lblpositiondynamicchange=lblpositiondynamicchange-3; } lbltextinbubbles.frame=cgrectmake(lblpositiondynamicchange, lbltextinbubbles.frame.origin.y, width, height); lblpositionwidth=lbltextinbubbles.frame.size.width; }else { if(lbltextinbubbles.frame.size.height < 125) { if( lblpositiondynamicchangey > 38 ) { lblpositiondynamicchangey=lblpositiondynamicchangey-10; } lbltextinbubbles.frame=cgrectmake(lbltextinbubbles.frame.origin.x, lblpositiondynamicchangey, lbltextinbubbles.frame.size.width, height); }else { nslog(@"%lu",(unsigned long)[lbltextinbubbles.text length]); } } lbltextinbubbles.linebreakmode=6; // nslog(@"after= %f",lbltextinbubbles.frame.origin.x); [self setbubblesimageframe]; } -(void)setbubblesimageframe { imgbabble.frame = cgrectmake(lbltextinbubbles.frame.origin.x -55, lbltextinbubbles.frame.origin.y-55, lbltextinbubbles.frame.size.width+100, lbltextinbubbles.frame.size.height+100); } - (ibaction)txt_editing:(id)sender { [self textheight]; lbltextinbubbles.textalignment = nstextalignmentcenter; /* if([txtmain.text length] > 16) { nslog(@"x=%f,y=%f,,,,, width=%f,,,,height=%fds",imgbabble.frame.origin.x,imgbabble.frame.origin.y,imgbabble.frame.size.width,imgbabble.frame.size.height); imgbabble.frame=cgrectmake(imgbabble.frame.origin.x-10, imgbabble.frame.origin.y-5, 160, 64); // nslog(@"x=%f,y=%f,,,,, width=%f,,,,height=%fds",imgbabble.frame.origin.x,imgbabble.frame.origin.y,imgbabble.frame.size.width,imgbabble.frame.size.height); }*/ lbltextinbubbles.text=txtmain.text; lbltextinbubbles.textcolor= [uicolor whitecolor]; lbltextinbubbles.layer.bordercolor=[uicolor whitecolor].cgcolor; lbltextinbubbles.layer.borderwidth=1.0; }
i suggest use stretchable images , define proper edge insets each one. can wrap around text rect:
uiimage *bubbleimage = [[uiimage imagewithcgimage:[uiimage imagenamed:@"imagebubble~iphone"].cgimage scale:1.0 orientation:uiimageorientationright] resizableimagewithcapinsets:uiedgeinsetsmake(13, 13, 13, 21) resizingmode:uiimageresizingmodestretch]; uiimageview *bubbleimageview = [[uiimageview alloc] initwithimage:bubbleimage]; bubbleimageview.autoresizingmask = uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth; bubbleimageview.frame = ...;
Comments
Post a Comment