I'm currently using Xcode 7.3 and I'm simply wondering how to select multiple buttons across different UIViews, but under a single view controller. CMD clicking doesn't seem to work. I need this functionality because in Xcode 7.3 the only way to let two buttons on IB to share the same action is to select them at once and then drag the action to your view controller. I'm doing this by code and no drag & drop
class LogIn: UIViewController {
var mail_tf : UITextField!
var pass_tf : UITextField!
var btnL : UIButton!
var btnC : UIButton!
let cl1 = UIColor (red: 255/255.0, green: 258/255.0, blue: 196/255.0, alpha: 1)
let cl2 = UIColor (red: 238/255.0, green: 233/255.0, blue: 191/255.0, alpha: 1)
override func loadView() {
super.loadView()
let backgroundView = UIImageView(image: UIImage(named: "4")!)
//backgroundView.layer.cornerRadius = backgroundView.frame.size.width / 2
backgroundView.frame = CGRectMake(0, 0, 900, 900)
//backgroundView.clipsToBounds = true
//backgroundView.layer.borderColor = UIColor.whiteColor().CGColor
// backgroundView.layer.borderWidth = 1
self.view.addSubview(backgroundView)
mail_tf = UITextField()
mail_tf.frame = CGRectMake(95, 90, 190, 60)
mail_tf.layer.cornerRadius = 10
mail_tf.layer.borderWidth = 1
mail_tf.layer.borderColor = UIColor.blackColor().CGColor
mail_tf.placeholder = "e-mail"
mail_tf.textColor = UIColor.redColor()
mail_tf.backgroundColor = cl1
mail_tf.borderStyle = UITextBorderStyle.RoundedRect
self.view.addSubview(mail_tf)
pass_tf = UITextField()
pass_tf.frame = CGRectMake(95, 190, 190, 60)
pass_tf.layer.cornerRadius = 10
pass_tf.layer.borderWidth = 1
pass_tf.layer.borderColor = UIColor.blackColor().CGColor
pass_tf.placeholder = "password"
pass_tf.secureTextEntry = true
pass_tf.textColor = UIColor.redColor()
pass_tf.backgroundColor = cl1
pass_tf.borderStyle = UITextBorderStyle.RoundedRect
self.view.addSubview(pass_tf)
btnL = UIButton()
btnL.frame = CGRectMake(195, 260, 90, 40)
btnL.setTitle("Log In ", forState: UIControlState.Normal)
btnL.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
btnL.layer.borderWidth = 1
btnL.layer.borderColor = UIColor.blackColor().CGColor
btnL.layer.cornerRadius = 10
btnL.backgroundColor = cl1
self.view.addSubview(btnL)
btnL.addTarget(self , action: #selector(self.action(_:)), forControlEvents: UIControlEvents.TouchUpInside)
btnC = UIButton()
btnC.frame = CGRectMake(228, 350, 150, 40)
btnC.setTitle("Create new account ", forState: UIControlState.Normal)
btnC.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
btnC.layer.borderWidth = 1
btnC.layer.borderColor = UIColor.blackColor().CGColor
btnC.layer.cornerRadius = 10
btnC.backgroundColor = cl1
self.view.addSubview(btnC)
btnC.addTarget(self , action: #selector(self.action(_:)), forControlEvents: UIControlEvents.TouchUpInside)
}
func action (sender: UIButton!) {
// btnL & btnC open the Logged_in file . there is the problem
let vc = Logged_In()
let navigation = UINavigationController(rootViewController:vc)
self.navigationController?.presentViewController(navigation, animated: true, completion: nil)
let vc1 = create()
let navigation1 = UINavigationController(rootViewController:vc1)
self.navigationController?.presentViewController(navigation1, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Log in"
self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: cl1]
}
}