I'm a beginner at developing for iOS, and after doing some research on the web, I still couldn't find a way that I can set a button to copy the entire text from a textview. I've seen some tutorials but most of them are old, and some of them are very confusing. Any help would be appreciated, thanks.
try this,
#IBAction func copyButton(sender: AnyObject) {
UIPasteboard.general.string = textToCopy.text
}
Related
So the QuickLookPreview displays correctly as usual, but when you try and use the Apple built-in sharesheet it is sliding up a see-through grey view that is displaying nothing else on it. Has anyone had experience with this?
Thought it might be something obscure like an alpha view in the background...
Appreciate any good suggestions.
So in our case this was being caused by an Activity extension that was not even being used anymore. Super weird bug that took quite a lot of digging to find, but posting it here just in case anyone else has similar weirdness one day and can have a better time of it.
extension UIActivityViewController {
override open func viewDidLoad() {
super.viewDidLoad()
//self.unusedfunction()
}
func unusedfunction() {
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UIActivityViewController.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.Theme.Black], for: .normal)
}
}
So the issue was being caused by the super.viewDidLoad() and we just had to delete/comment out that extension for the share feature to start displaying correctly again.
A quick question. I use to see the inferred type by option click the property or object on the left of a statement. After upgrade to Xcode 13, for instance, when I option click on below text property, there is no quick help popping up. Do u guys meet this same issue? Just Google it, no clue found.
let text = "Have a nice day"
Quick help is only shown when I option-click on an iOS built-in property, function, etc. It doesn't appear for custom defined things.
For code below, when I optional click on viewDidLoad or addSubview , I could get quick help menu popped up. But without luck for tableView, which is a user defined stuff.
private lazy var tableView: UITableView = {
let table = UITableView()
table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
return table
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableView)
tableView.frame = view.bounds
}
Well, restart your Mac will solve this problem. It seems I had not restarted my Mac since the day I upgrade to Xcode 13.
The issue link in Apple forum: link
For me restarting the Mac, cleaning build folder and derived data + quitting Xcode didn't help.
Seems like it works only on small projects, but not on the one for the company I work for. It's pretty random and extremely annoying, no idea what could fix it honestly
I wanted to make a kind of a notes app where users can add images inline with text, similar to how iOS' native Notes app does. Any advice on approaches I could take for this?
I'm new to iOS development and have been trying to teach myself a bunch of necessary skills and was curious as to how someone would go about doing this.
Thanks!
You can use UITextField to add images and text in one field, It can be done by using storyboard also and to do it programmatically is also convenient. Find the below code to add image programmatically in a text field :
var imageView = UIImageView()
var image = UIImage(named: "email.png")
imageView.image = image
emailField.leftView = imageView
emailField.leftViewMode = UITextFieldViewMode.always
emailField.leftViewMode = .always
UITextView is your best bet. It is not the most friendly UI component to work with if you are just starting out, but it is what Apple almost certainly uses for their Notes App, and supports inlining of text, images, hyperlinks, styles etc.
I'm making a custom keyboard in which you can copy an gif to clipboard when pressing a button.
I'm not getting to work so far. Even though I've tried the following
-(void)doWhenButtonPressed {
[UIPasteboard generalPasteboard].image = [UIImage imageNamed:#"my.gif"];
}
Now it does not copy anything, which I think is kind of strange, because it does copy the image when i it with this line in a normal application. So what am i doing wrong?
PS: I have even checked that I can actually acces 'my.gif' by adding it programmatically to a button...
PPS: And the method -(void)doWhenButtonPressed is called as well.
Okay so I finally found the answer myself :)
You have to set "RequestsOpenAccess" to "YES" in your Info.plist. Then you can copy an image to clipboard!
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)
}
You dont really need the "RequestOpenAccess" to be enabled to actually copy paste into a UITextView.
You just need to load your image into the UIPasteBoard general object and then you can paste it into a UITextView by long pressing and then choosing paste.
I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.
Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?
Thanks in advance
Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.
The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:
func insertText(_ text: String) //Swift
- (void)insertText:(NSString *)text //ObjC
These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.
Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.