0

Obj-Cで書かれたカスタムActivityIndi​​catorViewを使用しようとしています。インジケータをUIViewフレームにセンタリングするために必要なメソッドが含まれています。スウィフトコードで問題を使用しています。ここでは... GitHubのにSwiftのMONActivityViewメソッドを変換する方法

- (void)placeAtTheCenterWithView:(UIView *)view { 
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeCenterX 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:self.view 
                  attribute:NSLayoutAttributeCenterX 
                 multiplier:1.0f 
                  constant:0.0f]]; 

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:view 
                  attribute:NSLayoutAttributeCenterY 
                  relatedBy:NSLayoutRelationEqual 
                  toItem:self.view 
                  attribute:NSLayoutAttributeCenterY 
                 multiplier:1.0f 
                  constant:0.0f]]; 
} 

リンクは、私はスウィフトにこれを使用することができますどのようにhttps://github.com/mownier/MONActivityIndicatorView

コードですか?

答えて

1

これはあなたが探しているものですか?目的-cを迅速に変換しますか? ;)

func placeAtTheCenterWithView(view: UIView) { 
    let xCenterConstraint = NSLayoutConstraint(item: view, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1, constant: 0) 
    let yCenterConstraint = NSLayoutConstraint(item: view, attribute: .CenterY, relatedBy: .Equal, toItem: self.view, attribute: .CenterY, multiplier: 1, constant: 0) 
    self.view.addConstraints([xCenterConstraint, yCenterConstraint]) 
} 

乾杯:それはそう、ここに翻訳された場合

関連する問題