我不知道如何将以下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 ++;
}
}
答案 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
}