Paul Peelen
Paul Peelen

Reputation: 10329

Draw round-corner box

In my application I have a map, this map has a lot of annotations... but sometimes no location is found for an annotation (server couldn't find lat/lon). When this happens, I would like to draw a little box on my map with the text "Some locations could not be found" (or similar). I want this box to have round corners and to be transperant. Also, if possible I would prefer if this does not effect the functionality of the map. What I mean with that is that if the user draws its finger on the map from where that box is located, the map should still move.

How can I make such a box?

This is what I mean:
alt text

Best regards,
Paul Peelen

Upvotes: 0

Views: 543

Answers (2)

Brad
Brad

Reputation: 2237

There is some demo code at: http://www.eng.utah.edu/~cs4962/programming.html

In the solution for the color chooser. (In the top section)


+ (void) addRoundedRect:(CGRect)rect radiusPercent:(float)radiusPercent
{
    CGContextRef context = UIGraphicsGetCurrentContext();

CGFloat radius = fminf(rect.size.width, rect.size.height) * radiusPercent; CGFloat minX = CGRectGetMinX(rect); CGFloat midX = CGRectGetMidX(rect); CGFloat maxX = CGRectGetMaxX(rect); CGFloat minY = CGRectGetMinY(rect); CGFloat midY = CGRectGetMidY(rect); CGFloat maxY = CGRectGetMaxY(rect); CGContextMoveToPoint(context, minX, midY); CGContextAddArcToPoint(context, minX, minY, midX, minY, radius); CGContextAddArcToPoint(context, maxX, minY, maxX, midY, radius); CGContextAddArcToPoint(context, maxX, maxY, midX, maxY, radius); CGContextAddArcToPoint(context, minX, maxY, minX, midY, radius); CGContextClosePath(context);

}

Upvotes: 1

Echelon
Echelon

Reputation: 7922

Either use Photoshop :), or else do it using CALayer.

To do it with a layer, create a UIView called bgView with the appropriate alpha value for your background and then do this in the method where you want to display the alert panel:-

CALayer *layer = bgView.layer;
layer.masksToBounds = YES;
layer.cornerRadius = 20.0; // adjust for corner effect

Upvotes: 2

Related Questions