이렇게하면 모든 막대 버튼 항목의 너비를 계산합니다.
주요 아이디어는 그들의 순서는 중요하지 않은 것입니다 그리고 우리는 IBOutletCollection 사용할 수 있습니다
@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *allButtons;
및 방향 변경 전에 실행됩니다 코드에서 :
const CGFloat leftOrRightMargin = 12; // measured on a screenshot
const CGFloat gapBetweenButtons = 10; // measured on a screenshot
const CGFloat experimentalCorrection = 6; // don't ask why
int totalNumberOfButtons = 0;
CGFloat totalWidthOfButtons = 0.0;
for (UIButton *b in allButtons) {
if (b.superview) { // if it's visible
totalNumberOfButtons++;
totalWidthOfButtons += b.bounds.size.width;
}
}
CGFloat occupiedSpace = experimentalCorrection
+ 2 * leftOrRightMargin
// gaps: totalNumberOfButtons-1+1, the last one is for the slider
+ totalNumberOfButtons * gapBetweenButtons
+ totalWidthOfButtons;
// now, resize the slider control
방향 변경 후 :
[myBar setNeedsLayout];
UISearchBar를 사용하여이 작업을 수행하려고합니다 ... 나는 더러워진 솔을 찾지 못했을 것입니다. ution? –
IB에서 내 검색 창을 추가하면 방향 변경으로 크기가 조정 된 것 같습니다. 그런 다음 항목 수가 적은 툴바에서 항목을 다시 설정하면 검색 막대의 크기는 조정되지 않지만 이전 크기로 유지됩니다. 절망적이다. –