Да.
Если вы создаете UIView самостоятельно, вы можете делать все, что захотите.
Это не так сложно в вашем случае.Некоторые UILabels как подпредставления и некоторая логика в touchesDidSomething:withEvent:
, чтобы выяснить, какая метка находится рядом с прикосновением.
И метод делегата, который сообщает, какой раздел был затронут.
Я думаю, что мне может понадобиться что-то подобное, поэтому я решил попробовать.
//myIndexSelectorView.m
- (id)initWithFrame:(CGRect)frame andLabels:(NSArray *)l {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor lightGrayColor];
self.layer.cornerRadius = frame.size.width/2;
labels = [l retain];
NSInteger count;
for (NSString *string in labels) {
CGFloat margin = 5.0f;
CGFloat yPosition = count*(frame.size.height/[labels count]);
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(margin, yPosition, frame.size.width-2*margin, frame.size.height/[labels count])] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor darkGrayColor];
label.textAlignment = UITextAlignmentCenter;
label.text = string;
[self addSubview:label];
count++;
}
}
return self;
}
- (void)touch:(UITouch *)touch {
CGPoint touchPosition = [touch locationInView:self];
NSInteger index = touchPosition.y / (self.bounds.size.height / [labels count]);
NSLog(@"Touched: %@", [labels objectAtIndex:index]);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self touch:touch];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self touch:touch];
}
- (void)dealloc {
[labels release];
[super dealloc];
}
работает как положено и выглядит как селектор индекса uitableview
![enter image description here](https://i.stack.imgur.com/3lUss.png)
как обычно, я не проверял наличие ошибок, и это не должно быть решением для копирования и вставки.