Friday 27 October 2017

how switch to specific tab programmatically if click on button in UITabBarItem

I have a button in Viewcontroller in UITabBarItem, I want to switch to a specific tab

Just use this:
tabBarController?.selectedIndex = 1

Tuesday 24 October 2017

Cmd + click, jumping to definition in Xcode 9 issue?

If cmd+click is not working in Xcode 9, here is the solution

Xcode9-Preferences->Navigation->Command-click on Code:->Jump To Definition



if still not found

  1. File > Workspace Settings
  2. Click over the little grey arrow above Advanced... Button (Derived Data)
  3. Select my project folder and delete it.
  4. close the xcode and reopen clean and build 


Monday 16 October 2017

Call the event continuously on editing of Textfield



 override func viewDidLoad() {

        super.viewDidLoad()

textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
}


func textFieldDidChange(_ textField: UITextField) {
 print("event triggered")
}

Saturday 14 October 2017

Dashed line borders for UIView

var yourViewBorder = CAShapeLayer()
yourViewBorder.strokeColor = UIColor.black.cgColor
yourViewBorder.lineDashPattern = [2, 2]
yourViewBorder.frame = yourView.bounds
yourViewBorder.fillColor = nil
yourViewBorder.path = UIBezierPath(rect: yourView.bounds).cgPath
yourView.layer.addSublayer(yourViewBorder)

Wednesday 11 October 2017

Set cornerRadius separately bottom-left,bottom-right and top-left,top-right corner of a UIView?

extension UIView {
    func roundCorners(corners:UIRectCorner, radius: CGFloat) {
      let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
      let mask = CAShapeLayer()
      mask.path = path.cgPath
      self.layer.mask = mask
    }
}



usage:
YourView.roundCorners([.topLeft, .bottomLeft], radius: 10)

Remove bottom line in navigation bar

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