如何将以下Objective-C代码转换为swift

时间:2016-02-29 00:05:44

标签: ios objective-c swift

我不知道如何将以下Objective-C代码转换为Swift。我该怎么办?

-(void)layoutSubviews{

    for (UIView *view in self.subviews) {

        NSString *viewClass = NSStringFromClass([view class]);
        if (![viewClass isEqualToString:@"UITabBarButton"]) continue;

        CGFloat buttonX = buttonIndex * buttonW;
        if (buttonIndex >= 2) {
            buttonX += buttonW;
        }

        view.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
        buttonIndex ++;
    }
}

1 个答案:

答案 0 :(得分:0)

for view in self.subviews {
  guard view is UITabBarButton else {
    continue
  }

  var buttonX = buttonIndex * buttonW
  if buttonIndex >= 2 {
    buttonX += buttonW
  }
  view.frame = CGRect(x: buttonX, y: buttonY, width: buttonW, height: buttonH)
  buttonIndex += 1
}