2017-02-17 4 views
1
let containerViewWidth = 250 
let containerViewHeight = 120 

let containerFrame=CGRect(x: 10, y: 70, width: CGFloat(containerViewWidth), height: CGFloat(containerViewHeight)) 
let label=UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) 
label.text="anusha" 

var containerView: UIView = UIView(frame: containerFrame);    
containerView.addSubview(label) 
alert.view.addSubview(containerView) 

      // now add some constraints to make sure that the alert resizes itself 
let cons:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: containerView, attribute: NSLayoutAttribute.height, multiplier: 1.00, constant: 130) 

alert.view.addConstraint(cons) 

var cons2:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: containerView, attribute: NSLayoutAttribute.width, multiplier: 1.00, constant: 20) 

    alert.view.addConstraint(cons2) 
    alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.default, handler: nil)) 

Nachdem ich die Ansicht .... Schließen-Schaltfläche hinzufügen, funktioniert nicht ... wie diese Arbeit zu machen?iOS Alarm-View-Controller

Antwort

0

diese Codezeile

containerView.isUserInteractionEnabled = false 

hinzufügen, da Ihre containerView Ihre Close Button

+0

Buddy, und meine Schließen-Taste sollte unter dem Container sein View ... was sollte getan werden? –

-1
bedeckt

Nur eine zum Schließen Alarm mehr Taste.
bearbeiten ein wenig Code:

alert.addAction(UIAlertAction(title: "Close", style: .UIAlertActionStyle.default, handler: { (action) in 
     // Do some thing 
     print("Do") 
     })) 
0

ich Ihren Code versucht hatte, und es funktioniert, völlig

I-Code nur hinzufügen, hatte es zu präsentieren,

Werfen Sie einen Blick auf sie,

let alert:UIAlertController = UIAlertController() 
    let containerViewWidth = 250 
    let containerViewHeight = 120 

    let containerFrame=CGRect(x: 10, y: 70, width: CGFloat(containerViewWidth), height: CGFloat(containerViewHeight)) 
    let label=UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) 
    label.text="anusha" 

    let containerView: UIView = UIView(frame: containerFrame); 
    containerView.addSubview(label) 
    alert.view.addSubview(containerView) 

    // now add some constraints to make sure that the alert resizes itself 
    let cons:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: containerView, attribute: NSLayoutAttribute.height, multiplier: 1.00, constant: 130) 

    alert.view.addConstraint(cons) 

    let cons2:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: containerView, attribute: NSLayoutAttribute.width, multiplier: 1.00, constant: 20) 

    alert.view.addConstraint(cons2) 
    alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.default, handler: nil)) 

    self.present(alert, animated: true, completion: nil)