2013-09-27 70 views
0

我在我的應用程序中使用了SBTableAlert庫,但在iOS 7中,此庫不起作用。 我修復了它,增加了TSAlertView,對話框顯示正常。 但我的問題是,按鈕的位置不是它應該的。在SBTableAlert中設置按鈕位置

我設置按鈕的位置:

-(void)willPresentTableAlert:(SBTableAlert *)tableAlert{ 
    int counter = 0; 
    for (id view_sub in self.filterAlert.view.subviews) { 
     if ([view_sub isKindOfClass:[UIButton class]]) { 
      switch (counter) { 
       case 0: 
        ((UIButton*)view_sub).frame = CGRectMake(10, 
                 10, 
                 144, 
                 44); 
        ((UIButton*)view_sub).backgroundColor = [UIColor redColor]; 
        break; 
       case 1: 
        ((UIButton*)view_sub).frame = CGRectMake(169, 
                    150, 
                    144, 
                    44); 
        break; 
       case 2: 
        ((UIButton*)view_sub).frame = CGRectMake(328, 
                    150, 
                    144, 
                    44); 
        break; 

       default: 
        break; 
      } 
      counter++; 
     } 
    } 
} 

的事情是,按鈕被塗成紅色,但幀組一行忽略,而不是內層,它們被放在一個下的其他進出警報框架。

回答

0

我終於找到了答案。 問題出在TSAlertVeiw庫中,因爲它具有函數recalcSizeAndLayout:佈局,它在末尾調用並覆蓋按鈕的自定義位置。

的解決方案是在TSAlertView customLayoutOfButton添加新BOOL變量,然後自動佈局之前檢查你的按鈕:

if (!self.customLayoutOfButton) { 
     CGFloat buttonHeight = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero].height; 
     if (stacked) 
     { 
      CGFloat buttonWidth = maxWidth; 
      for (UIButton* b in self.buttons) 
      { 
       b.frame = CGRectMake(kTSAlertView_LeftMargin, y, buttonWidth, buttonHeight); 
       y += buttonHeight + kTSAlertView_RowMargin; 
      } 

     } 
     else 
     { 
      CGFloat buttonWidth = (maxWidth - kTSAlertView_ColumnMargin)/2.0; 
      CGFloat x = kTSAlertView_LeftMargin; 
      for (UIButton* b in self.buttons) 
      { 
       b.frame = CGRectMake(x, y, buttonWidth, buttonHeight); 
       x += buttonWidth + kTSAlertView_ColumnMargin; 
      } 
     } 
}