Skip to content

Commit

Permalink
MaxWidth property
Browse files Browse the repository at this point in the history
  • Loading branch information
x2on committed May 20, 2011
1 parent a83dc64 commit 41058c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMPopTipView/CMPopTipView.h
Expand Up @@ -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;
Expand Down
38 changes: 30 additions & 8 deletions CMPopTipView/CMPopTipView.m
Expand Up @@ -39,6 +39,7 @@ @implementation CMPopTipView
@synthesize textColor;
@synthesize textFont;
@synthesize animation;
@synthesize maxWidth;

- (void)drawRect:(CGRect)rect {

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 41058c6

Please sign in to comment.