Iphone 在UIView中添加垂直字母选择器
嗨 我可以添加我们在UITableView、UIView中使用的垂直字母选择器吗?Iphone 在UIView中添加垂直字母选择器,iphone,objective-c,uitableview,alphabet,Iphone,Objective C,Uitableview,Alphabet,嗨 我可以添加我们在UITableView、UIView中使用的垂直字母选择器吗? 致以最诚挚的问候如果您谈论的是键盘,那么除了默认位置之外,无法将其定位,原因是苹果不允许更改其位置。希望这能帮助您。谢谢。如果您谈论的是键盘,然后,由于苹果不允许更改其位置的原因,不能将其定位为默认位置以外的位置。希望这对您有所帮助。谢谢。是的 如果您自己创建UIView,您可以做任何您想做的事情 对你来说都没那么难。一些UI标签作为子视图,一些逻辑在触摸屏中做了一些事情:withEvent:以确定哪个标签靠近触
致以最诚挚的问候如果您谈论的是键盘,那么除了默认位置之外,无法将其定位,原因是苹果不允许更改其位置。希望这能帮助您。谢谢。如果您谈论的是键盘,然后,由于苹果不允许更改其位置的原因,不能将其定位为默认位置以外的位置。希望这对您有所帮助。谢谢。是的 如果您自己创建UIView,您可以做任何您想做的事情 对你来说都没那么难。一些UI标签作为子视图,一些逻辑在
触摸屏中做了一些事情: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的索引选择器类似
像往常一样,我没有检查bug,这不应该是复制粘贴解决方案 是的
如果您自己创建UIView,您可以做任何您想做的事情
对你来说都没那么难。一些UI标签作为子视图,一些逻辑在触摸屏中做了一些事情: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的索引选择器类似
像往常一样,我没有检查bug,这不应该是复制粘贴解决方案 您可以使用不同的UILabel,并为它们设置标签。现在,要检测相应标签上的触摸,可以使用UIAPTgestureRecognitor类您可以使用不同的UILabel,并为其设置标记。现在,为了检测适当标签上的触摸,您可以使用UITAPPATURURERECGNONZER类我认为他指的是在中间的图像中可以看到的字母条:不是键盘。不,我不是在谈论键盘,我想要在UITableviewYeah使用的UIVIEW右侧的竖直字母表,呃…部分…东西。哦,对不起,我误解了。。!!我想他指的是在中间的图片中可以看到的字母条:不是键盘。不,我不是在谈论键盘,我想要在我的UIVIEW右侧使用的垂直字母表,我们在UITableviewYeah使用,呃……节……哦,对不起,我误解了……!所以你说我将对所有字母使用不同的UILabel,并将在每个UILabel上附加一些触摸事件?当用户触摸任何UILabel时,我将执行附加到该UILabel的后台逻辑?我做对了吗?我会把触摸逻辑放在视图中。因此,您可以跟踪轻敲和移动。就像tableview中所做的那样,你说我将对所有字母使用不同的UILabel,并将在每个UILabel上附加一些触摸事件?当用户触摸任何UILabel时,我将执行附加到该UILabel的后台逻辑?我做对了吗?我会把触摸逻辑放在视图中。因此,您可以跟踪轻敲和移动。就像tableview中的一样