![]() So, keep on reading to find out some really interesting stuff. Even if you won’t use what we’ll build here eventually, you might get some ideas to apply in your own solutions. I’ll show you how to create a handy tool that you’ll be able to use right when it’s needed, and you won’t need to worry anymore about all that I described above. In this tutorial I will present you a simple, yet quite effective recipe that makes fetching remote images and then handling them locally a really straightforward task. The answers though should not be given and implemented when an actual application is being built that kind of issues should be already fixed and be part of the solution, not the problem. Are there any rules about naming or storing details? Are there best and worst practices one should follow? Should images be stored in documents or in caches directory? These and more questions will most probably arise when building an app and it’s about time to deal with remote images. Have you seen this maybe? A perfect chaos and no consistency at all!Īnother troubling point can be the way images are handled locally once they are fetched. It would be really bad to see the app displaying the wrong avatar next to each name, and it would be even worse to have avatar images being replaced by other avatar images when contacts appear and disappear while scrolling. Displaying fetched avatar images to the proper contacts can end up being a hell depending on how image handling has been implemented. Think of the contact list again, which is a list of images with text at its simplest form. When fetching multiple images then it’s really easy to display the wrong image to the wrong place in certain cases. What makes things complicated is the fact that image fetching is an asynchronous process. Their images must be fetched and handled by the app, and displayed properly when necessary. Or, another example, think of an app that manages the event of a worldwide convention, and among its features is the list of all attendees. ![]() When users connect to the app then avatars must be downloaded in order to be used by the app. Those contacts have avatar images residing to a server. For instance, suppose that you’re building the next great messaging application where obviously users have contacts. One of the most common tasks that iOS -and not only- developers are called to perform in their programming endeavours is fetching and managing remote images that should be displayed to an app. In viewDidLoad of your ViewController, do this: navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem. Improving on JP Aquino's code for Swift 5 for share action rightBarButtonItem on the Navigation Controller. plain, target: self, action: #selector(share(sender:)))Ĭreate the function func share(sender:UIView) On ViewDidLoad navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Share", style. This is how I implemented sharing with Swift 4/5 using a right button on the Navigation Controller. ![]() Self.present(activityViewController, animated: true, completion: nil) ,ĪctivityViewController.isModalInPresentation = true ] as? UIActivityItemsConfigurationReadingĪctivityViewController.excludedActivityTypes = [ ![]() This line remove the arrow of the popover to show in iPadĪctivityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.downĪctivityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)ĪctivityViewController.activityItemsConfiguration = [ This lines is for the popover you need to show in iPadĪctivityViewController.popoverPresentationController?.sourceView = (sender as! UIButton) Let activityViewController : UIActivityViewController = UIActivityViewController(ĪctivityItems:, applicationActivities: nil) Let image : UIImage = UIImage(named: "your-image-name")! Let secondActivityItem : NSURL = NSURL(string: "")! Let firstActivityItem = "Description you want."
0 Comments
Leave a Reply. |