ios - How to add "Copy" option to text? -
ios - How to add "Copy" option to text? -
i have text in "bubble" fitting text within image shown below. works fine except text not copyable. need have "copy" alternative when user tab on text (or bubble image") "cop" options displayed, in when user tab built in sms message bubble.
#import "speechbubbleview.h" static uifont* font = nil; static uiimage* lefthandimage = nil; static uiimage* righthandimage = nil; const cgfloat vertpadding = 4; // additional padding around edges const cgfloat horzpadding = 4; const cgfloat textleftmargin = 17; // insets text const cgfloat textrightmargin = 15; const cgfloat texttopmargin = 10; const cgfloat textbottommargin = 11; const cgfloat minbubblewidth = 50; // minimum width of bubble const cgfloat minbubbleheight = 40; // minimum height of bubble const cgfloat wrapwidth = 200; // maximum width of text in bubble @implementation speechbubbleview + (void)initialize { if (self == [speechbubbleview class]) { font = /*[*/ [uifont systemfontofsize:[uifont systemfontsize]] /*retain]*/; lefthandimage = /*[*/ [[uiimage imagenamed:/*@"bubblelefthand"*/@"lefttest4"] stretchableimagewithleftcapwidth:20 topcapheight:19] /*retain]*/; righthandimage = /*[*/[[uiimage imagenamed:/*@"bubblerighthand"*/@"righttest4"] stretchableimagewithleftcapwidth:20 topcapheight:19] /*retain]*/; } } + (cgsize)sizefortext:(nsstring*)text { cgsize textsize = [text sizewithfont:font constrainedtosize:cgsizemake(wrapwidth, 9999) linebreakmode:uilinebreakmodewordwrap]; cgsize bubblesize; bubblesize.width = textsize.width + textleftmargin + textrightmargin; bubblesize.height = textsize.height + texttopmargin + textbottommargin; if (bubblesize.width < minbubblewidth) bubblesize.width = minbubblewidth; if (bubblesize.height < minbubbleheight) bubblesize.height = minbubbleheight; bubblesize.width += horzpadding*2; bubblesize.height += vertpadding*2; homecoming bubblesize; } - (void)drawrect:(cgrect)rect { [self.backgroundcolor setfill]; uirectfill(rect); cgrect bubblerect = cgrectinset(self.bounds, vertpadding, horzpadding); cgrect textrect; textrect.origin.y = bubblerect.origin.y + texttopmargin; textrect.size.width = bubblerect.size.width - textleftmargin - textrightmargin; textrect.size.height = bubblerect.size.height - texttopmargin - textbottommargin; if (bubbletype == bubbletypelefthand) { [lefthandimage drawinrect:bubblerect]; textrect.origin.x = bubblerect.origin.x + textleftmargin; } else { [righthandimage drawinrect:bubblerect]; textrect.origin.x = bubblerect.origin.x + textrightmargin; } [[uicolor blackcolor] set]; [text drawinrect:textrect withfont:font linebreakmode:uilinebreakmodewordwrap]; } - (void)settext:(nsstring*)newtext bubbletype:(bubbletype)newbubbletype { //[text release]; /** handle local **/ // text = [newtext copy]; text = [newtext copy]; bubbletype = newbubbletype; [self setneedsdisplay]; } - (void)dealloc { //[text release]; //[super dealloc]; } @end
if want scheme cut/copy/paste menu (or subset thereof) without total suite of text editability features uitextfield
or uitextview
, need nowadays own uimenucontroller
. doing requires:
copy:
) want support you perform event handling nowadays menu controller @ appropriate time (e.g. gesture recognizer action) as case, there's a tutorial on nshipster both swift , objc sample code. kudos @mattt, though i'd line needs correction:
if you’re wondering why, oh why, isn’t built uilabel
, well… bring together club.
"join club" should replaced "file bug". sorta rhymes!
ios objective-c uikit
Comments
Post a Comment