diff --git a/CMPopTipView/CMPopTipView.h b/CMPopTipView/CMPopTipView.h index 780bc22..db176d9 100644 --- a/CMPopTipView/CMPopTipView.h +++ b/CMPopTipView/CMPopTipView.h @@ -124,6 +124,7 @@ typedef enum { @property (nonatomic, retain) UIColor *textColor; @property (nonatomic, retain) UIFont *textFont; @property (nonatomic, assign) CMPopTipAnimation animation; +@property (nonatomic, assign) CGFloat maxWidth; - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated; - (void)presentPointingAtBarButtonItem:(UIBarButtonItem *)barButtonItem animated:(BOOL)animated; diff --git a/CMPopTipView/CMPopTipView.m b/CMPopTipView/CMPopTipView.m index ca1c8f3..fd22bd7 100644 --- a/CMPopTipView/CMPopTipView.m +++ b/CMPopTipView/CMPopTipView.m @@ -39,6 +39,7 @@ @implementation CMPopTipView @synthesize textColor; @synthesize textFont; @synthesize animation; +@synthesize maxWidth; - (void)drawRect:(CGRect)rect { @@ -203,15 +204,36 @@ - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerVie // Size of rounded rect CGFloat rectWidth; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - // iPad - rectWidth = containerView.frame.size.width/3; - } - else { - // iPhone - rectWidth = containerView.frame.size.width*2/3; - } + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + // iPad + if (maxWidth) { + if (maxWidth < containerView.frame.size.width) { + rectWidth = maxWidth; + } + else { + rectWidth = containerView.frame.size.width - 20; + } + } + else { + rectWidth = containerView.frame.size.width/3; + } + } + else { + // iPhone + if (maxWidth) { + if (maxWidth < containerView.frame.size.width) { + rectWidth = maxWidth; + } + else { + rectWidth = containerView.frame.size.width - 10; + } + } + else { + rectWidth = containerView.frame.size.width*2/3; + } + } + CGSize textSize = [self.message sizeWithFont:textFont constrainedToSize:CGSizeMake(rectWidth, 99999.0) lineBreakMode:UILineBreakModeWordWrap];