I have a UITextView and i want to paste text into that UITextView with button's click event.
You know , when i click a button , the copied text from anywhere paste into that UITextView.
How can i do that?
Thanks in advance.
-(IBAction)buttonPressed:(id)sender
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
MsgtextView.text = [NSString stringWithFormat:#"%# %#",MsgtextView.text,pasteboard.string;
}
Check this
You can use the UIPasteboard class.
Try this code
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
textView.text = pasteboard.string;
Related
I'm trying to create app-specific UIPasteboard, but have some problems figuring out how to register it:
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:#"myPasteboard" create:YES];
If I just create it, app continues to use generalPasteboard. I really hope that I don't have to catch cut/copy/paste operations and set items manually.
Please read this article
http://nshipster.com/uimenucontroller/ (It's about UILabel, not UITextField but is useful just for example and information about how copy/paste/edit actions work and how you can customize its' behavior)
I think you need to subclass UITextField to MyTextField for example, and override -(void)copy: and -(void)paste: methods from UIResponderStandardEditActions.
In your implementation of these methods you should use your custom UIPasteboard to copy text into and paste from it, like mentioned in this answer,
How to do copy/paste function programmatically in iphone?
but instead of using [UIPasteboard generalPasteboard] use [UIPasteboard pasteboardWithName:#"myPasteboard" create:YES]
//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];
Below is a Tutorial about Pasteboard.
http://hayageek.com/uipasteboard-example-read-write-share/
//pasteboard initialization
let pasteBoard = UIPasteboard.general
// copying the content of textview to pasteboard
if(pasteBoard.hasStrings){
pasteBoard.string = textViewPB.text
}
//pasting the content of pasteboard to textview
if(pasteBoard.hasStrings){
textViewPB.text = pasteBoard.string
}
I am creating Custom GIF Keyboard in iOS8 using app extension. I was created layout of my custom keyboard. I was implement LongPress Gesture for selecting GIF Image but its not work. so what can i do for this or any suggestion regarding to this?
- (void)textWillChange:(id<UITextInput>)textInput {
[self.textDocumentProxy insertText:#"Hi"];
}
I also tried with UITextInputDelegate mentioned above.
This method is also deals with only text append. But My concern is to load gif or png image in input area.
I have done with long press gesture and make a method for touch handler.
-(void)tapped:(id)sender
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
UIImage *image = [UIImage imageNamed:#"img_temp.gif"];
NSData *imgData = UIImagePNGRepresentation(image);
[pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
}
I also given become first responder aswell.
-(BOOL)canBecomeFirstResponder
{
return YES;
}
I can copy text in pasteboard, but I can't copy .gif or .png image.
What Popkey, for example, are doing is copy the clicked GIF to the pasteboard.
The user then needs to long click their rich text field and paste the content into their iMessage for example.
You couldn't load a gif directly in the input area. To do that you have to copy the gif to the pasteboard and then paste the gif in the input area.
To copy the gif into the pasteboard you need to convert it into the NSData.
Here is the demo code in Swift 3.0.
let pb = UIPasteboard.general
let data = NSData(contentsOfURL: url)
if data != nil
{
self.pb.setData(data!, forPasteboardType: kUTTypeGIF as String)
}
I have the following lines in my code to add a clickable url to a UITextView. merchantwebsite is my UITextView.
self.merchantwebsite.attributedText = [[NSAttributedString alloc] initWithString:#"http://www.crossfit.com" attributes:#{NSLinkAttributeName: #"http://www.crossfit.com"}];
self.merchantwebsite.userInteractionEnabled = YES;
When I click on the UITextView, the app crashes with the log
2014-03-19 16:13:43.051 BTLE[27103:60b] -[__NSCFConstantString scheme]: unrecognized selector sent to instance 0x1a4404
Can someone please tell me what i'm doing wrong.
Thanks!
You evidently have code that expects the URL to be an NSURL. But, quite simply, an NSString is not an NSURL. Try it like this:
self.tv.attributedText =
[[NSAttributedString alloc]
initWithString:#"http://www.crossfit.com"
attributes:
#{NSLinkAttributeName: [NSURL URLWithString:#"http://www.crossfit.com"]}];
Just type the link in when you are telling the UITextView what to display and then turn on link recognition in the settings on the right when your UITextView is selected from the .storyboard page.
You don't really need any of the code that you have all you need is:
merchantwebsite.text = #"http://www.crossfit.com";
Change your code as follows:
NSAttributedString *string = [[NSAttributedString alloc] initWithString:#"http://www.crossfit.com" attributes:#{NSLinkAttributeName: #"http://www.crossfit.com"}];
[self.merchantwebsite setAttributedText:string];
Really quick, easy question.How do I add text to a UITextView, when it's already populated.
E.G., but doesn't work: _textView.text=+#"";
Thanks,
SebOH
_textView.text = [_textView.text stringByAppendingString:#""]
_textView.text = [_textView.text stringByAppendingString:#"Additional Text"];
_textView.text = [NSString stringWithFormat:#"%#%#",_textView.text,#"text you want to append"];
using above you can add the text where ever you want prefix,postfix ..
After recovering from sleep mode (tap sleep/wake button and then tap home button), I tried to get pasteboard string with the code blow and the result was nil.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
self.beforeValue = pasteboard.string;
I can get it with iPhone 4S(iOS5.1.1), iPodtouch4G(iOS6.1.3), iPad(iOS6.1.3) but I cannot with 5(iOS6.1.3). Is it iPhone5 bug? Any hint is appreciated.