iPhone에서 UISegmentedControl을 두 행으로 확장 할 수 있습니까? 이 작업은 몇 가지 응용 프로그램에서 수행되었지만 문서에서 필요한 항목을 찾지 못했습니다. UISegmentedControl처럼 보이도록 디자인 된 커스텀 UIButton 일 수도 있습니다.두 행 UISegmentedControl
2
A
답변
0
표준 UISegmentedControl
을 사용할 수 없습니다. 직접 작성해야합니다.
1
나는 이것을 찾고 있었다.
나는 심지어 두 번째 행이 첫 번째 행의 일부처럼 보일 때까지 그리드와 비슷하게 보이기를 원했습니다. 두 번째 UISegmentedControl 만 사용하고 불필요한 둥근 모서리를 처리하기 위해 다른 트릭과 결합 할 수 있습니다. 내가 UIControl (UIView의에서 상속)에서 상속 내 구현, 추가 2 UISegmentControls, 가장자리를 클립 그들을 하나로 보이게하는 2 UIViews에서
.
텍스트 필드를 시각적으로 가운데로 설정하기 위해 몇 가지 조정을합니다.
가로로 쉽게 확장 할 수 있으며 약간의 노력으로 세 번째로 ... 행을 추가 할 수도 있습니다.
헤더 :
// YHSegmentedGridControl.m
// UITestSegment2D
// Created by Yh on 22/04/13.
#import "YHSegmentedGridControl.h"
@implementation YHSegmentedGridControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self initWithDefaults];
}
return self;
}
실제 작업 :
-(void) initWithDefaults{
a = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: @"1", @"2", nil]];
b = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: @"3", @"4", nil]];
float e = 75;
int d = (int)e/7;
[a setFrame:CGRectMake(0, 0, 2*e, e+2*d)];
[b setFrame:CGRectMake(0, -2*d, 2*e, e+2*d)];
[a setContentOffset:CGSizeMake(0, -d) forSegmentAtIndex:0];
[a setContentOffset:CGSizeMake(0, -d) forSegmentAtIndex:1];
[b setContentOffset:CGSizeMake(0, +d) forSegmentAtIndex:0];
[b setContentOffset:CGSizeMake(0, +d) forSegmentAtIndex:1];
[a addTarget:self
action:@selector(pickOne:)
forControlEvents:UIControlEventValueChanged];
[b addTarget:self
action:@selector(pickOne:)
forControlEvents:UIControlEventValueChanged];
va = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2*e, e)];
vb = [[UIView alloc] initWithFrame:CGRectMake(0, e, 2*e, e)];
[va setClipsToBounds:YES];
[vb setClipsToBounds:YES];
[self setFrame:CGRectMake(0,0,2*e,2*e)];
[va addSubview:a];
[vb addSubview:b];
[self addSubview:va];
[self addSubview:vb];
}
- (void)setSelectedSegmentIndex:(NSInteger)index{
if(index == UISegmentedControlNoSegment){
[a setSelectedSegmentIndex:UISegmentedControlNoSegment];
[b setSelectedSegmentIndex:UISegmentedControlNoSegment];
} else if(index < a.numberOfSegments){
[a setSelectedSegmentIndex:index];
[b setSelectedSegmentIndex:UISegmentedControlNoSegment];
} else if(index < (a.numberOfSegments + b.numberOfSegments)){
[b setSelectedSegmentIndex:(index - a.numberOfSegments)];
[a setSelectedSegmentIndex:UISegmentedControlNoSegment];
}else
NSLog(@"No such segment: index to high");
}
- (NSInteger)selectedSegmentIndex{
if(a.selectedSegmentIndex != UISegmentedControlNoSegment)
return a.selectedSegmentIndex;
else if(b.selectedSegmentIndex != UISegmentedControlNoSegment)
return b.selectedSegmentIndex + a.numberOfSegments;
else
return UISegmentedControlNoSegment;
return 0;
}
- (void)pickOne:(id)sender{
if(sender == a)
[b setSelectedSegmentIndex:UISegmentedControlNoSegment];
if(sender == b)
[a setSelectedSegmentIndex:UISegmentedControlNoSegment];
//notify
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
@end
하는 .m 파일에서
// YHSegmentedGridControl.h
#import <UIKit/UIKit.h>
@interface YHSegmentedGridControl : UIControl{
UISegmentedControl *a,*b;
UIView *va,*vb;
}
- (void)setSelectedSegmentIndex:(NSInteger)index;
- (NSInteger)selectedSegmentIndex;
@end
관련 문제
- 1. UISegmentedControl 동작
- 2. AppDelegate의 UISegmentedControl
- 3. 장소 UISegmentedControl
- 4. 두 행 사이에 행 삽입
- 5. UISegmentedControl 항상 0
- 6. 이상한 UISegmentedControl 문제!
- 7. UISegmentedControl 숨겨진 문제 설정
- 8. UISegmentedControl 및 대상 추가
- 9. - UITabBarItem의 UISegmentedControl 업데이트 -
- 10. UISegmentedControl 이미지 배율
- 11. UISegmentedControl 대리자/터치 이벤트
- 12. UISegmentedControl 사용자 지정
- 13. UISegmentedControl autoresizingMask가 작동하지 않습니다.
- 14. UINavigationBar에서 두 개의 "행"
- 15. 두 열의 행 축소
- 16. Core Data, UITableView 및 UISegmentedControl
- 17. NSUserdefaults에 UISegmentedControl 상태를 저장하는 방법
- 18. UINavigationBar/Item에 포함 된 UISegmentedControl
- 19. UISegmentedControl 및 UINavigationController에 대한 질문
- 20. iOS NSUserDefaults에 UISegmentedControl 선택 저장
- 21. UISegmentedControl - Interface Builder에서 높이 변경
- 22. UISegmentedControl 선택된 색조가 표시되지 않음
- 23. 두 행 사이에 공백 추가
- 24. 레이블 태그를 사용하는 두 행
- 25. UISegmentedControl 버튼에 다른 색상을 설정하는 방법은 무엇입니까?
- 26. UISegmentedControl - 2 UITableViews 사이를 전환하는 방법
- 27. SQL 두 테이블의 데이터 선택 (한 행 -> 여러 행)
- 28. UISegmentedControl : UIToolbar에서 사용하면 이벤트가 발생하지 않습니다.
- 29. UISegmentedControl like iTunes/App Store apps
- 30. UISegmentedControl 및 UITableView 조합에 일부 Pizzaz 추가