Wednesday, 21 June 2017

Go to rootView when tabBar tapped

import UIKit

class RootviewTabViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        let rootView = self.viewControllers![self.selectedIndex] as! UINavigationController
        rootView.popToRootViewController(animated: false)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

  
}

Tuesday, 20 June 2017

How to dismiss number keyboard after tapping outside of the textfield

viewdidload()
{
let tapRecognizer = UITapGestureRecognizer()
tapRecognizer.addTarget(self, action: #selector(ViewController.didTapView))
self.view.addGestureRecognizer(tapRecognizer)
}

func didTapView(){
  self.view.endEditing(true)
}

Sunday, 18 June 2017

How to center align the cells of a UICollectionView?

https://stackoverflow.com/questions/13588283/how-to-center-align-the-cells-of-a-uicollectionview

Wednesday, 14 June 2017

Hiding the tabbar and removing the space

https://stackoverflow.com/questions/37040313/hiding-the-tabbar-and-removing-the-space/37108450

Wednesday, 7 June 2017

Swift iOS TableView cell items disappears when scrolling

https://stackoverflow.com/questions/44341768/when-calling-prepareforreuse-in-customtableviewcell-swift-uitableviewcells-be

Execute action when back bar button of UINavigationController is pressed

https://stackoverflow.com/questions/27713747/execute-action-when-back-bar-button-of-uinavigationcontroller-is-pressed


self.navigationItem.hidesBackButton = true
        let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(Quoterequestsend.back(sender:)))

        self.navigationItem.leftBarButtonItem = newBackButton




  func back(sender: UIBarButtonItem) {
        
        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        
        let vc = storyBoard.instantiateViewController(withIdentifier: "viewcontroller") as! viewcontroller
        
        self.navigationController?.pushViewController(vc, animated: true)
    }

Monday, 5 June 2017

Scrollview and keyboard Swift



@IBOutlet weak var scrollView: UIScrollView!

viewdidload()
{
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name:NSNotification.Name.UIKeyboardWillShow, object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name:NSNotification.Name.UIKeyboardWillHide, object: nil)
}

 func keyboardWillShow(notification:NSNotification){
        //give room at the bottom of the scroll view, so it doesn't cover up anything the user needs to tap
        var userInfo = notification.userInfo!
        var keyboardFrame:CGRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
        keyboardFrame = self.view.convert(keyboardFrame, from: nil)
        
        var contentInset:UIEdgeInsets = self.scrollView.contentInset
        contentInset.bottom = keyboardFrame.size.height
        self.scrollView.contentInset = contentInset
    }
    
    func keyboardWillHide(notification:NSNotification){
        let contentInset:UIEdgeInsets = UIEdgeInsets.zero
        self.scrollView.contentInset = contentInset
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        self.view.endEditing(true)
        return false

    }


textfield should be delegate if we want to work with return key function 

Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...