Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:29:48+00:00 2026-05-22T12:29:48+00:00

Please provide the code to make a tip balloon programmatically, like Grindr has. I

  • 0

Please provide the code to make a tip balloon programmatically, like Grindr has.

I want it to be sized automatically, based on the text & font-size.
And, I want to be able to change the location of the arrow.
If it’s on an end, it should be a right triangle. Otherwise, it should be an eqilateral triangle.

tip balloon

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:29:49+00:00Added an answer on May 22, 2026 at 12:29 pm
    // AppDelegate.h
    
    @interface AppDelegate : NSObject <UIApplicationDelegate> {
    
    }
    
    @property (nonatomic, retain) UIWindow *window;
    
    @end
    
    // AppDelegate.m
    
    #import "AppDelegate.h"
    #import "TipBalloon.h"
    
    @implementation AppDelegate
    
    @synthesize window;
    
    #pragma mark NSObject
    
    - (void)dealloc {
        [window release];
        [super dealloc];
    }
    
    #pragma mark UIApplicationDelegate
    
    - (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        // Add the tip balloon.
        TipBalloon *textExample =
        [[TipBalloon alloc] initAtPoint:CGPointMake(6.0f, 30.0f) withText:
         @"Hello world! I like to make things. Yay! They are really cool things!"];
        [window addSubview:textExample];
        [textExample release];
    
        window.backgroundColor = [UIColor brownColor];
        [window makeKeyAndVisible];
        return YES;
    }
    
    @end
    
    // TipBalloon.h
    
    @interface TipBalloon : UIView {
    
    }
    
    @property (nonatomic, copy) NSString *text;
    
    - (id)initAtPoint:(CGPoint)point withText:(NSString *)string;
    - (void)drawOutlineInContext:(CGContextRef)context;
    - (void)drawTextInContext:(CGContextRef)context;
    
    @end
    
    // TipBallon.m
    
    #import "TipBalloon.h"
    
    // TODO make some of these instance variables to add more customization.
    static const CGFloat kArrowOffset = 0.0f;
    static const CGFloat kStrokeWidth = 2.0f;
    static const CGFloat kArrowSize = 14.0f;
    static const CGFloat kFontSize = 12.0f;
    static const CGFloat kMaxWidth = 196.0f;
    static const CGFloat kMaxHeight = CGFLOAT_MAX;
    static const CGFloat kPaddingWidth = 12.0f;
    static const CGFloat kPaddingHeight = 10.0f;
    
    @implementation TipBalloon
    
    @synthesize text;
    
    #pragma mark NSObject
    
    - (void)dealloc {
        [text release];
        [super dealloc];
    }
    
    #pragma mark UIView
    
    - (void)drawRect:(CGRect)rect {
        [super drawRect:rect];
        CGContextRef contextRef = UIGraphicsGetCurrentContext();
        [self drawOutlineInContext:contextRef];
        [self drawTextInContext:contextRef];
    }
    
    #pragma mark TipBalloon
    
    - (id)initAtPoint:(CGPoint)point withText:(NSString *)string {
        CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:kFontSize]
                         constrainedToSize:CGSizeMake(kMaxWidth, kMaxHeight)
                             lineBreakMode:UILineBreakModeWordWrap];
        CGRect rect = CGRectMake(point.x, point.y, size.width+kPaddingWidth*2.0f,
                                 size.height+kPaddingHeight*2.0f+kArrowSize);
        if ((self = [super initWithFrame:rect])) {
            self.text = string;
            UIColor *clearColor = [[UIColor alloc] initWithWhite:0.0f alpha:0.0f];
            self.backgroundColor = clearColor;
            [clearColor release];
        }
        return self;
    }
    
    - (void)drawOutlineInContext:(CGContextRef)context {
        CGRect rect = self.bounds;
        rect.origin.x += (kStrokeWidth/2.0f);
        rect.origin.y += kStrokeWidth + kArrowSize;
        rect.size.width -= kStrokeWidth;
        rect.size.height -= kStrokeWidth*1.5f + kArrowSize;
    
        CGFloat radius = 11.0f;
        CGFloat x_left = rect.origin.x;
        CGFloat x_right = x_left + rect.size.width;
        CGFloat y_top = rect.origin.y;
        CGFloat y_bottom = y_top + rect.size.height;
    
        CGContextBeginPath(context);
        CGContextSetLineWidth(context, kStrokeWidth);
        CGContextSetRGBStrokeColor(context, 0.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f, 1.0f); // green
        CGContextSetGrayFillColor(context, 1.0f, 1.0f); // white background
        CGContextMoveToPoint(context, x_left+radius, y_top);
        CGContextAddLineToPoint(context, x_left+radius+kArrowOffset, y_top);
    
        // Draw triangle.
    //    CGContextAddLineToPoint(context, x_left+radius+kArrowOffset+kArrowSize/2.0f, y_top-kArrowSize);
        CGContextAddLineToPoint(context, x_left+radius+kArrowOffset, y_top-kArrowSize);
        CGContextAddLineToPoint(context, x_left+radius+kArrowOffset+kArrowSize, y_top);
    
        static const CGFloat F_PI = (CGFloat)M_PI;
        CGContextAddArc(context, x_right-radius, y_top+radius, radius, 3.0f*F_PI/2.0f, 0.0f, 0);
        CGContextAddArc(context, x_right-radius, y_bottom-radius, radius, 0.0f, F_PI/2.0f, 0);
        CGContextAddArc(context, x_left+radius, y_bottom-radius, radius, F_PI/2.0f, F_PI, 0);
        CGContextAddArc(context, x_left+radius, y_top+radius, radius, F_PI, 3.0f*F_PI/2.0f, 0);
        CGContextClosePath(context);
        CGContextDrawPath(context, kCGPathFillStroke);
    }
    
    - (void)drawTextInContext:(CGContextRef)context {
        CGRect rect = self.bounds;
        rect.origin.x += kPaddingWidth;
        rect.origin.y += kPaddingHeight + kArrowSize;
        rect.size.width -= kPaddingWidth*2.0f;
        rect.size.height -= kPaddingHeight*2.0f;
    
        CGContextSetGrayFillColor(context, 0.0f, 1.0f); // black text
        [text drawInRect:rect withFont:[UIFont systemFontOfSize:kFontSize]
           lineBreakMode:UILineBreakModeWordWrap];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please, provide code examples in a language of your choice. Update : No constraints
Has anybody used OProfile tool on android...If you are able to profile please provide
e.preventDefault() is not working in my IE6. Could you please provide some code to
To make my code more readable, I like to avoid names of objects that
Please provide tips for effectively using git with svn. What are your best practices?
Please provide a good, thorough tutorial about Java class loading , focusing on how
Please provide the diff b/w ref and out parameters in C#
Can someone please provide an example of creating a Java ArrayList and HashMap on
Can anyone please provide a link to download the .NET 3.5 SDK? I checked
If this is possible, please provide a sample query or two so I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.