2016-07-28 42 views
1

Ich versuche, ein Textfeld innerhalb eines UIAlertController in Swift in iOS 9.3 zu implementieren, irgendwie bekomme ich Polsterung und einen oberen Rand um das Textfeld.Entfernen Polsterung und Rahmen um TextField in UIAlertController

Bitte beachten Sie den folgenden Screenshot, ich habe einen dicken Rahmen um das Textfeld hinzugefügt, um die Polsterung und oberen Rand/Linie zu markieren.

Screenshot

Der Code für meine 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) 
} 

Dieses Verhalten scheint seltsam, und ich kann es nicht referenziert finden, wenn für ein ähnliches Problem zu suchen.

+0

Sie haben den borderWith auf 4.0 gesetzt und das ist der Grund, warum Sie eine Grenze sehen. Entferne diese Linie und der Rand wird verschwinden. –

+0

@ChristianAbella Dieser Rand ist nur da, um das Padding/Randproblem um ihn herum darzustellen. Hier ist es ohne die Grenze: http://i.imgur.com/5gckZVu.png](http://i.imgur.com/5gckZVu.png) – iamlolz

+0

welche Polsterung möchten Sie entfernt werden? oben links? –

Antwort

0

Die Funktion constraintEqualToConstant ist nur für iOS 9.0 verfügbar, Sie müssen Ihrem Code eine Überprüfung hinzufügen, wenn Sie eine iOS-Version älter als 9.0 unterstützen möchten. Dies könnte derjenige sein, der das Problem verursacht.

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

Ich stelle dies auf einem iOS 9.3-Gerät bereit, daher glaube ich nicht, dass dies das Problem ist. Danke für den Vorschlag. – iamlolz