2016-08-30 56 views

回答

0

它在ViewController行250-272中聲明。 defaultContentView是一個函數。

/** 
    Create content view 

    :param: width  CGFloat 
    :param: height CGFloat 
    :param: imageName String 

    :returns: UIView 
    */ 
    func defaultContentView(width:CGFloat,height:CGFloat, imageName:String, offSet:CGFloat = -200) -> UIView { 
     var contentView = UIView(frame: CGRectMake(0, 0, width, height)) 


     // create the title label 
     let titleLabel = UILabel(frame: CGRectMake(0, 0, width, 30)) 
     titleLabel.text = "Example blabla, Cool popup !" 
     titleLabel.textAlignment = .Center 
     titleLabel.font = UIFont.systemFontOfSize(17) 
     contentView.addSubview(titleLabel) 

     contentView.setTranslatesAutoresizingMaskIntoConstraints(false) 


     titleLabel.autoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | 
      UIViewAutoresizing.FlexibleRightMargin | 
      UIViewAutoresizing.FlexibleTopMargin | 
      UIViewAutoresizing.FlexibleBottomMargin 
     titleLabel.center = CGPointMake(view.bounds.midX, view.bounds.midY + offSet) 
     self.defaultImage(contentView,name: imageName) 

     return contentView 
    } 
+0

是的,我知道,但defaultContentView,但它之前被稱爲它被稱爲其他?它可以創建不在ViewController? –

+0

我不認爲你明白...'defaultContentView'是一個_function_,它返回一個'UIView'。這不是一個在任何地方聲明的變量。例如,在這一行中,'let contentView = self.defaultContentView ...'指定'contentView'作爲defaultContentView()的返回值。 – random