Objective C - 在iOS 8的Action Sheet中更改文本大小

时间:2014-10-16 23:13:22

标签: ios objective-c ios8 uialertcontroller

我有一个已在iOS 7上运行的iPad应用程序。我曾使用此代码缩小操作表按钮中的文本大小:

- (void) willPresentActionSheet:(UIActionSheet *)actionSheet {
  for (UIView *subview in actionSheet.subviews) {
    if ([subview isKindOfClass:[UIButton class]]) {
      UIButton *button = (UIButton *)subview;
      button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:17.0];
    }
  }
}

我正在寻找一种在iOS 8上使用UIAlertControllerUIAlertAction执行相同操作的方法。虽然UIAlertController包含子视图的视图,但它似乎没有UIButtonUILabel

1 个答案:

答案 0 :(得分:0)

你可以在iOS8上做到这一点。只需将UIAlertController子类化,请检查以下代码:

@interface AlertController : UIAlertController

@end

@implementation AlertController

- (void)viewWillLayoutSubviews {
  [super viewWillLayoutSubviews];

  // Search for labels and change font
  [self changeLabelsFontInView:self.view];
}

- (void)changeLabelsFontInView:(UIView *)view {
  if (view.subviews.count > 0) {
    for (UIView *subview in view.subviews) {
      [self changeLabelsFontInView:subview];
    }
  } else {
    if ([view isKindOfClass:[UILabel class]]) {
      [(UILabel *)view setFont:[UIFont boldSystemFontOfSize:35.0F]];
    }
  }
}

@end