とても初歩的なことで申し訳ないのですが、ボタンが表示されません。
左上にスコアボタン、右上にランキングボタンを表示させたいです。
スコアボタンのコードだけをかくとスコアというタイトルのボタンが左上に表示されるところまではいいのですが、
その後ランキングのコードをかくと、xの値を何にしてもコードのボタンがランキングのボタンと置きかわり、ランキングというタイトルのボタンが左上に表示されてしまいます。
イニシャライザなどの設定がおかしいのでしょうか?
よろしくお願いいたします。
swift
1class TopView: UIView { 2 3 4 /// このビューのコントローラー 5 var topViewController: TopViewController! 6 7 override init(frame: CGRect) { 8 super.init(frame: frame) 9 10 self.isUserInteractionEnabled = false 11 12 //背景色 13 self.backgroundColor = (UIColor.white) 14 15 //画面のサイズ 16 self.frame = CGRect(x:0, y:0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height) 17 18 //タッチ可にする 19 self.isUserInteractionEnabled = true 20 21 //スタートボタン 22 let startbtn = UIButton(frame: CGRect(x: UIScreen.main.bounds.size.width/2-65, y: 250, width:260 / 2, height: 106 / 2)) 23// startbtn.setImage(UIImage(named: "gameUI_itemGetPop_btn_tojiru_260x106"), for: UIControlState()) 24 startbtn.setTitle("スタート", for: UIControlState.normal) 25 startbtn.setTitleColor(UIColor.black, for: UIControlState.normal) 26 startbtn.addTarget(nil, action: #selector(TopViewController.goToTrapGameViewController), for: .touchUpInside) 27 self.addSubview(startbtn) 28 29 //スコアボタン 30 let scorebtn = UIButton(frame: CGRect(x: 25, y: 50, width:260 / 2, height: 106 / 2)) 31 scorebtn.setTitle("スコア", for: UIControlState.normal) 32 scorebtn.setTitleColor(UIColor.black, for: UIControlState.normal) 33 scorebtn.addTarget(nil, action: #selector(TopViewController.tapButton), for: .touchUpInside) 34 self.addSubview(scorebtn) 35 36 //ランキングボタン 37 let rankbtn = UIButton(frame: CGRect(x: UIScreen.main.bounds.size.width-25-130, y: 50, width:260 / 2, height: 106 / 2)) 38 scorebtn.setTitle("ランキング", for: UIControlState.normal) 39 scorebtn.setTitleColor(UIColor.black, for: UIControlState.normal) 40 scorebtn.addTarget(nil, action: #selector(TopViewController.tapRankButton), for: .touchUpInside) 41 self.addSubview(rankbtn) 42 43 44 45 46 47}//大括弧
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/06 08:40