so, i'm using swift library ImageSlideshow and use KingfisherSource to set image. I get the url image from Alamofire request
How to make loading/activity indicator before image showed?
Here's my code:
var arrayImage = [InputSource]()
for data in items{
let Menu = ModelBanner()
Menu.id = (data["id"].intValue)
Menu.banner = (data["banner"].stringValue)
self.listBanner.append(Menu)
self.arrayImage.append(KingfisherSource(urlString: data["banner"].stringValue)!)
}
self.slideImage.contentScaleMode = .scaleAspectFill
self.slideImage.setImageInputs(self.arrayImage)
You can add activity indicator from the storyboard over your UIImageView.
Connect an outlet from the activity indicator to your ViewController file
In viewDidLoad(), activityIndicator.hidesWhenStopped = true
Within your Alamofire request, use activityIndicator.startAnimating()
Once you get the call back from Alamofire, in the completion handler, use activityIndicator.stopAnimating()
Above code assumes activityIndicator is the outlet connection name of the UIActivityIndicatorView
Better way to show activity indicator is to use the default implementation.
slideshow.activityIndicator = DefaultActivityIndicator()
You can customize style and color of the indicator:
slideshow.activityIndicator = DefaultActivityIndicator(style: .white, color: nil)
There's also an option to use your own activity indicator. You just need to implement ActivityIndicatorView and ActivityIndicatorFactory protocols.
For more details see the Activity Indicator section here.
Related
I'm trying to implement google's placepicker for ios.
There is some demo code at:
https://github.com/googlemaps/maps-sdk-for-ios-samples/tree/master/GooglePlacePicker/GooglePlacePickerDemos
And i get most of it except the line in the file PickAPlaceViewController.swift
var mapViewController: BackgroundMapViewController?
In the github repo Google have provided their own class BackgroundMapViewController.
Do I need to create an instance of this class to use the place picker?
Or can I just use a GMSMapView like I ordinarily would with google maps.
Thanks.
For Google Places Controller you just need below code to show or present Places Controller in your App.
Put this in ur Button Action method :
// Create a place picker. Attempt to display it as a popover if we are on a device which
// supports popovers.
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
placePicker.modalPresentationStyle = .popover
placePicker.popoverPresentationController?.sourceView = pickAPlaceButton
placePicker.popoverPresentationController?.sourceRect = pickAPlaceButton.bounds
// Display the place picker. This will call the delegate methods defined below when the user
// has made a selection.
self.present(placePicker, animated: true, completion: nil)
Hope This will helps to show Place Picker in your app.
So, I'm trying to make this:
i tried using UIView in back of Status bar and set the color to orange, but when running, The UIView displayed right under the status bar, so it's still White
i'm trying many solution in the internet but none of them work. Yes it works but when i move to other view controller and back again, The color dissapeared. What should I do? i'm using swift
UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().clipsToBounds = true
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.backgroundColor = UIColor.orange
Try using this code in your appDelegate's method application didFinishLaunchingWithOptions
So I have been out of the iOS coding world for a bit and I am going through Swift at the moment.
In Objective-C I was able to change an image on the fly, but to do so I had to set the image delegate. The other reason I set the delegate was so I could hide the UIImageView
In Swift I seem to have an issue with this.
With the playground I can do this fine:
let responseImageView:UIImageView!
responseImageView.hidden = true
But in the project this does not work.
Can someone help me out here?
In my project I have this code :
#IBOutle var responseImageView: UIImageView!
//Inside a function I have this:
let smile = "smile.png"
imageName = UIImage(named: smile)!
responseImageView = UIImageView(image: imageName)
That code does not work.
And I can't hide the image by doing this:
responseImageView.hidden = true
If you created the actual UIImageView in the Storyboard or Interface Builder (and connected the IBOutlet correctly - it's always a good idea to double check this if something isn't working as expected!) you should not try to instantiate it again in code just to change the image. Instead, change the image by accessing the UIImageView's .image property, like so:
let smile = "smile.png"
let image = UIImage(named: smile)
responseImageView.image = image
Edit:
Just to clarify: by "instantiate" I specifically mean this line from you project code:
responseImageView = UIImageView(image: imageName)
Doing this in your function will break the connection you've set up in the storyboard. If you put a break point after that line or a println("\(responseImageView.superview)") you'll see that your instance of responseImageView is now no longer attached to a superview (explaining why you can change it's image or hide or unhide it all you want - you'll never see any change in the app).
I'm currently attempting to make a global activity indicator in swift, which is called whenever a fetch to the api is made. The idea is that the activity indicator will appear in the top left of a navigation bar (navigation view controller's child), and is available on every app page.
Can't show example image due to new account / low rep
I have the activity indicator displaying correctly, I'm just not sure on how to make it available from any page on the app - i've considered an extension, but am not sure on what the best way to approach it is. Any help would be greatly appreciated.
Activity Indicator Code:
let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
var activityItem = UIBarButtonItem()
func navBarActivity() {
// Call navBarActivity() to start activity indicator
// Use navigationItem.leftBarButtonItem = nil to stop activity indicator
activityIndicator.startAnimating()
activityIndicator.hidden = false
self.activityItem = UIBarButtonItem(customView: activityIndicator)
self.navigationItem.leftBarButtonItem = activityItem
}
I would recommend extension like this.
extension UIViewController {
func displayNavBarActivity() {
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .White)
indicator.startAnimating()
let item = UIBarButtonItem(customView: indicator)
self.navigationItem.leftBarButtonItem = item
}
func dismissNavBarActivity() {
self.navigationItem.leftBarButtonItem = nil
}
}
Call self.displayNavBarActivity() before api call, and call self.dismissNavBarActivity() after api call done.
However, I want you to check networkActivityIndicatorVisible of UIApplication. Consider using this option.
Specify YES if the app should show network activity and NO if it should not. The default value is NO. A spinning indicator in the status bar shows network activity. The app may explicitly hide or show this indicator.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instp/UIApplication/networkActivityIndicatorVisible
How do I change the colour of the top bar of the customisation page of the more view controller. Please see the linked image. Sorry I can't post image here because of my low reputation.
Screenshot Image
Edited with more info:
I have managed to change the background color using the following code. But cant change the color of the top bar.
func tabBarController(tabBarController: UITabBarController, willBeginCustomizingViewControllers viewControllers: [AnyObject]) {
var editView : UIView = tabBarController.view.subviews[1] as! UIView
editView.backgroundColor = UIColor.blackColor()
}
Basically 2 Ways you can achieve this if you are using Global Unique colour in the app for All navigation bar
Use this Solution on App Launch:
UINavigationBar.appearance().barTintColor = UIColor.redColor()
Or if you want to change the Color of More navigationcontroller only then
Use this Solution by getting the Tabbar Reference :
self.tabBarController?.moreNavigationController.navigationBar.barTintColor = UIColor.greenColor()
You can use second solution in the First viewcontroller of the Tab, because that contains your tabbar reference