主要是用到了一个自定义的CMPopTipView,使用起来还是挺简单的,具体的实现请参考附件。
- (IBAction)buttonAction:(id)sender { [self dismissAllPopTipViews]; if (sender == currentPopTipViewTarget) { self.currentPopTipViewTarget = nil; } else { NSString *contentMessage = nil; UIView *contentView = nil; id content = [self.contents objectForKey:[NSNumber numberWithInt:[(UIView *)sender tag]]]; if ([content isKindOfClass:[UIView class]]) { contentView = content; } else if ([content isKindOfClass:[NSString class]]) { contentMessage = content; } else { contentMessage = @"A CMPopTipView can automatically point to any view or bar button item."; } NSArray *colorScheme = [colorSchemes objectAtIndex:foo4random()*[colorSchemes count]]; UIColor *backgroundColor = [colorScheme objectAtIndex:0]; UIColor *textColor = [colorScheme objectAtIndex:1]; CMPopTipView *popTipView; if (contentView) { popTipView = [[[CMPopTipView alloc] initWithCustomView:contentView] autorelease]; } else { popTipView = [[[CMPopTipView alloc] initWithMessage:contentMessage] autorelease]; } popTipView.delegate = self; if (backgroundColor && ![backgroundColor isEqual:[NSNull null]]) { popTipView.backgroundColor = backgroundColor; } if (textColor && ![textColor isEqual:[NSNull null]]) { popTipView.textColor = textColor; } popTipView.animation = arc4random() % 2; popTipView.dismissTapAnywhere = YES; [popTipView autoDismissAnimated:YES atTimeInterval:3.0]; if ([sender isKindOfClass:[UIButton class]]) { UIButton *button = (UIButton *)sender; [popTipView presentPointingAtView:button inView:self.view animated:YES]; } else { UIBarButtonItem *barButtonItem = (UIBarButtonItem *)sender; [popTipView presentPointingAtBarButtonItem:barButtonItem animated:YES]; } [visiblePopTipViews addObject:popTipView]; self.currentPopTipViewTarget = sender; } }