2016-07-28 1 views
1

iOS 9.3のSwiftでUIAlertController内にテキストフィールドを実装しようとしていますが、どうやらパディングとテキスト枠の上の境界線が表示されています。UIAlertControllerのpaddingとborderFieldを削除します。

下のスクリーンショットを参照してください。パディングと上の境界線を強調表示するために、テキストフィールドの周りに太い枠線を追加しました。

Screenshot

私UIAlertControllerのためのコード:

func handleLoginForgotPassword() { 
    // create alert controller 
    let alertController = UIAlertController(title: "Password Reset", message: "\nEnter your email below and press Reset to reset your password.\n", preferredStyle: .Alert) 

    // create text field for email 
    alertController.addTextFieldWithConfigurationHandler { textField -> Void in 
     let tf = textField 
     tf.placeholder = "Email Address" 
     tf.autocorrectionType = .No 
     tf.autocapitalizationType = .None 
     tf.backgroundColor = UIColor.whiteColor()  

     tf.layer.borderWidth = 4.0 
     tf.heightAnchor.constraintEqualToConstant(50).active = true 

     // pull email from emailTextField if it exists 
     tf.text = self.emailTextField.text 
    } 

    // create "OK" alert action 
    let actionReset = UIAlertAction(title: "Reset", style: UIAlertActionStyle.Default) { 
     UIAlertAction in 
     NSLog("YES Pressed") 

     // do something 

     return 
    } 
    // create "Cancel" alert action 
    let actionCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { 
     UIAlertAction in 
     NSLog("NO Pressed")  

     // do something 

     return 
    } 

    // add the actions 
    alertController.addAction(actionReset) 
    alertController.addAction(actionCancel) 

    // present the controller 
    self.presentViewController(alertController, animated: true, completion: nil) 
} 

この動作は奇妙に思えると私は同様の問題を検索するとき、それは参照を見つけることができません。

+0

borderWithを4.0に設定しているため、境界線が表示されます。その行を削除すると、境界線が消えます。 –

+0

@ChristianAbellaその境界は、その周りのパディング/ボーダーの問題を説明するためだけにあります。ここには境界線がありません:[http://i.imgur.com/5gckZVu.png](http://i.imgur.com/5gckZVu.png) – iamlolz

+0

どのパッドを削除しますか?左上? –

答えて

0

constraintEqualToConstant関数は、iOS 9.0からのみ使用できます。9.0より古いiOSバージョンをサポートする場合は、コードにチェックを追加する必要があります。これが問題の原因となる可能性があります。

if #available(iOS 9.0, *) 
{ 
    tf.heightAnchor.constraintEqualToConstant(50).active = true 
} else 
{ 
    // Fallback on earlier versions 
} 
+0

これをiOS 9.3デバイスに導入しているので、これは問題ではないと思います。提案していただきありがとうございます。 – iamlolz

関連する問題