iOS: how to customize the view for dial pop - swift5

I want to show something when the dial pop up view shown like the screen capture, please how can I do with Swift?

I didn't quite get that question but if you wanna do something when you keyboard pops up you can do it in searchBarTextDidBeginEditing() which is an delegate method for UISearchBar
https://developer.apple.com/documentation/uikit/uisearchbardelegate/1624303-searchbartextdidbeginediting
if you wanna know more about custom UIAlert than refer this YouTube video
https://www.youtube.com/watch?v=u6TpJrZNuPU
if You wanna present something when your actionSheet is presented than you can directly add the animation programmatically after presenting the Alert
for example I presented a view after presenting an UIAlerActionSheet
self.present(alert, animated: true)
let view1 = UIView(frame: CGRect(x: 100, y: 100, width: 200, height: 200))
view1.backgroundColor = UIColor.red
view.addSubview(view1)
here view1 is presented and when needed you can remove that view1 from its superView so that it will vanish
view1.removeFromSuperview()

Related

Exist way notify when custom UIView will be presented or removeFromSuperview()?

I am create custom UIView using this code:
lazy var temporary: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.backgroundColor = .white
return view
}()
Exist way use NotificationCenter notify when this view will be presented and removed from VC if I am use:
self.view.addSubview(temporary)
or
temporary.removeFromSuperview()
I'm not totally sure what you are asking. I think you're asking for a way to tell when your custom view is added as a subview of another view.
The easiest way to do that is to make your view a custom subclass of UIView, and implement didMoveToSuperview() or willMove(toSuperview:). Those methods get called when your view is added as a child view of another view.
If you really want to use the notification center you could have your custom view class broadcast a notification when it gets added to a superview.

place NavigationBar subview behind the NavigationBarItem and title

I want to add a view below everything that's on the navigationBar. I need to add them as subviews to my NavigationBar so that they appear on any detail ViewController.
Here is what I tried so far inside my custom NavigationBar subclass (I call this method inside layoutSubviews()):
private var backgroundView = UIView()
backgroundView.frame = CGRect(x: 0, y: 0, width: 100, height: 70)
backgroundView.backgroundColor = .blue
backgroundView.alpha = 0.7
self.insertSubview(backgroundView, at: 0)
And this is what I get:
The backgroundView appears on top of the title and the NavigationBarItem.
What can I do?
According to this post on the apple developer forum, you can do this inside the NavigationBar class (which works!):
self.subviews[0].insertSubview(backgroundView, at: 0)

How to set an image as title in all navigation bars in swift?

I need to know if it is possible to add an image as title on all navigation controllers, this mean, that every controller that had a navigation bar had the same image title.
I used the next code to set an image as title in the navigation bar, but I have to set it on every viewController, the idea its for example set it on AppDelegate as UINavigationBar.appereance() or similar.
let imageView = UIImageView(image: UIImage(named: "my_image.png")!)
imageView.contentMode = .scaleAspectFit
let titleView = UIView(frame: CGRect(x: 0, y: 0, width: 107, height: 30))
imageView.frame = titleView.bounds
titleView.addSubview(imageView)
self.navigationItem.titleView = titleView
So the idea is to set this image as the default title for every controller, that way I will just need to configure it one time.
It is that posible? If not, What possible solution do you think that I can apply ?
The title view is a property of each view controller, not the navigation bar or navigation controller.
So start with a UIViewController subclass whose navigation item has this title view, and make all your other view controllers be subclasses of that.
Please try below code,
let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView
if this not works please share the screenshot.

AKSwiftSlideMenu activity indicator

I am using the AKSwiftSlideMenu project from the web and trying to put an activity indicator so it will display the indicator when the user pressed the menu bars on the top right. I tried everything. is there a way once the user pressed the 3menubar at the top to display a activity indicator until the menu appear from the side.
I do some database processing to build the menu item before the slide out.
Since AKSwiftSlideMenu is using UINavigationController, you can just add UIActivityIndicator on the right side of the navigation controller.
Something like that:
func showActivityIndicator() {
let activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
let barButton = UIBarButtonItem(customView: activityIndicator)
self.navigationItem.setRightBarButton(barButton, animated: true)
activityIndicator.startAnimating()
}
Don't forget, you need to prevent the Segue from happening, and halt the program until you are done loading.

Making a UITabBarButton trigger a modal segue

I want to mimic Instagram's tabbar functionality, where the middle option acts as a button that triggers a modal slide up segue instead of switching views like a normal tabbar button.
I don't know the correct way of doing this, but I'm trying to place a button directly over the middle tabbar button, but when pressing it it triggers the tabbar button instead of the normal button.
let count = CGFloat(tabBar.items!.count)
let itemSize = CGSize(width: tabBar.frame.size.width / count, height: tabBar.frame.height)
for (index, _) in tabBar.items!.enumerate() {
if index == 2 {
let xPosition = itemSize.width * CGFloat(index)
let backgroundButton = UIButton(frame: CGRect.init(x: xPosition, y: 0, width: itemSize.width, height: itemSize.height))
backgroundButton.backgroundColor = UIColor.redColor()
backgroundButton.addTarget(self, action: #selector(MainTabBarController.testButton), forControlEvents: .TouchUpInside)
//testButton just triggers a print statement for now
tabBar.insertSubview(backgroundButton, atIndex: 1)
}
}
When I press the middle button, it just triggers the normal view switching like with any other tabbar button, and does not print anything out meaning the overlayed button is never trigger.
Is there somewhere I went wrong, or better yet is there a better way of doing this? Prehaps making the tabbar button itself trigger a modal segue instead of the typical tabbar button behavior?