如何为 Swift 转换 MONActivityView 方法
How to convert MONActivityView Method for Swift
我正在尝试使用用 Obj-C 编写的自定义 ActivityIndicatorView。它包含在 UIView 框架中将指示器居中所需的方法。我在 Swift 代码中使用它时遇到问题。这是代码...
- (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]];
}
link到GitHub是https://github.com/mownier/MONActivityIndicatorView
如何在 Swift 中使用它?
这是您要找的吗?将 objective-c 转换为 swift ?如果是这样,这是翻译:
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])
}
干杯;)
我正在尝试使用用 Obj-C 编写的自定义 ActivityIndicatorView。它包含在 UIView 框架中将指示器居中所需的方法。我在 Swift 代码中使用它时遇到问题。这是代码...
- (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]];
}
link到GitHub是https://github.com/mownier/MONActivityIndicatorView
如何在 Swift 中使用它?
这是您要找的吗?将 objective-c 转换为 swift ?如果是这样,这是翻译:
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])
}
干杯;)