带箭头圆角的 uiview 代码例子

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#define ORC_RADIUS 12
@interface MapTipView : UIView {
    CGPoint origin;
    CGPoint point;
    CGSize size;
    UIFont *font;
    UILabel *label;
    NSString *title;
    UIButton *button;
    UIBezierPath *path;
}
@property (nonatomic, retain) NSString *title;
-(void)set_path;
-(id) init:(CGPoint) p str:(NSString*) str;
-(void)set_point:(CGPoint)p;
-(void) set_title:(NSString*) str;
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
@end
@implementation MapTipView
@synthesize title;
-(id) init:(CGPoint) p str:(NSString*) str
{
    if([super init] == nil)
        return nil;
    path = [[UIBezierPath alloc] init];
    label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    [label setBackgroundColor: [UIColor clearColor]];
    font = [UIFont systemFontOfSize:15.0];
    label.font = font;
    button = [[UIButton alloc] init];
    [button setBackgroundColor: [UIColor clearColor]];
    [button setTitle:@">" forState:UIControlStateNormal];
    [self setBackgroundColor: [UIColor clearColor]];
    [self setAlpha:0.8];
    [self addSubview: label];
    [self addSubview: button];
    [self set_point: p];
    [self set_title: str];
    return (self);
}
-(void)set_point:(CGPoint)p
{
    point = p;
}
- (void)drawRect:(CGRect)rect {
    [[UIColor grayColor] setFill];
    [path fill];
}
-(void) set_title:(NSString*) str
{
    label.text = str;
    CGSize csize;
    csize.width = 250;
    csize.height = 60;
    size = [str sizeWithFont:font constrainedToSize: csize
                  lineBreakMode: UILineBreakModeTailTruncation];
   
    label.frame = CGRectMake(10, 3, size.width, size.height);
    button.frame = CGRectMake(20+size.width, 3, 50, size.height);
    size.height += 30;
    size.width += 60;
    double bw = (size.width - ORC_RADIUS*3)/2;
    double x = point.x - bw;
    double y = point.y - size.height;
    origin.x = x;
    origin.y = y;
    self.frame = CGRectMake(origin.x, origin.y, size.width, size.height);
    [self set_path];
}
- (BOOL)pointInside:(CGPoint)p withEvent:(UIEvent *)event
{
    return [path containsPoint:p];
}
-(void)set_path
{
    double h = size.height - ORC_RADIUS*3;
    double bw = (size.width - ORC_RADIUS*3)/2;
    CGPoint p = CGPointMake(ORC_RADIUS, 0);
    [path moveToPoint:p];
    p.x += size.width - ORC_RADIUS*2;
    [path addLineToPoint: p];
    p.y += ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1414926*1.5
                  endAngle:0
                 clockwise:YES];
    p.x += ORC_RADIUS;
    p.y += h;
    [path addLineToPoint: p];
   
    p.x -= ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:0
                  endAngle:3.1415926/2.0
                 clockwise:YES];
    p.y += ORC_RADIUS;
    p.x -= bw;
    [path addLineToPoint: p];
   
    p.x -= ORC_RADIUS/2;
    p.y += ORC_RADIUS;
    [path addLineToPoint: p];
    p.x -= ORC_RADIUS/2;
    p.y -= ORC_RADIUS;
    [path addLineToPoint: p];
    p.x -= bw;
    [path addLineToPoint: p];
    p.y -= ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1415926/2.0
                  endAngle:3.1415926
                 clockwise:YES];
    p.x -= ORC_RADIUS;
    p.y -= h;
    [path addLineToPoint: p];
    p.x += ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1415926
                  endAngle:3.1415926*1.5
                 clockwise:YES];
    [path closePath];
}
- (void) dealloc
{
    [label release];
    [title release];
    [path release];
    [super dealloc];
}
@end

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

#define ORC_RADIUS 12
@interface MapTipView : UIView {
    CGPoint origin;
    CGPoint point;
    CGSize size;
    UIFont *font;
    UILabel *label;
    NSString *title;
    UIButton *button;
    UIBezierPath *path;
}
@property (nonatomic, retain) NSString *title;
-(void)set_path;
-(id) init:(CGPoint) p str:(NSString*) str;
-(void)set_point:(CGPoint)p;
-(void) set_title:(NSString*) str;
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
@end
@implementation MapTipView
@synthesize title;
-(id) init:(CGPoint) p str:(NSString*) str
{
    if([super init] == nil)
        return nil;
    path = [[UIBezierPath alloc] init];
    label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    [label setBackgroundColor: [UIColor clearColor]];
    font = [UIFont systemFontOfSize:15.0];
    label.font = font;
    button = [[UIButton alloc] init];
    [button setBackgroundColor: [UIColor clearColor]];
    [button setTitle:@">" forState:UIControlStateNormal];
    [self setBackgroundColor: [UIColor clearColor]];
    [self setAlpha:0.8];
    [self addSubview: label];
    [self addSubview: button];
    [self set_point: p];
    [self set_title: str];
    return (self);
}
-(void)set_point:(CGPoint)p
{
    point = p;
}
- (void)drawRect:(CGRect)rect {
    [[UIColor grayColor] setFill];
    [path fill];
}
-(void) set_title:(NSString*) str
{
    label.text = str;
    CGSize csize;
    csize.width = 250;
    csize.height = 60;
    size = [str sizeWithFont:font constrainedToSize: csize
                  lineBreakMode: UILineBreakModeTailTruncation];
   
    label.frame = CGRectMake(10, 3, size.width, size.height);
    button.frame = CGRectMake(20+size.width, 3, 50, size.height);
    size.height += 30;
    size.width += 60;
    double bw = (size.width - ORC_RADIUS*3)/2;
    double x = point.x - bw;
    double y = point.y - size.height;
    origin.x = x;
    origin.y = y;
    self.frame = CGRectMake(origin.x, origin.y, size.width, size.height);
    [self set_path];
}
- (BOOL)pointInside:(CGPoint)p withEvent:(UIEvent *)event
{
    return [path containsPoint:p];
}
-(void)set_path
{
    double h = size.height - ORC_RADIUS*3;
    double bw = (size.width - ORC_RADIUS*3)/2;
    CGPoint p = CGPointMake(ORC_RADIUS, 0);
    [path moveToPoint:p];
    p.x += size.width - ORC_RADIUS*2;
    [path addLineToPoint: p];
    p.y += ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1414926*1.5
                  endAngle:0
                 clockwise:YES];
    p.x += ORC_RADIUS;
    p.y += h;
    [path addLineToPoint: p];
   
    p.x -= ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:0
                  endAngle:3.1415926/2.0
                 clockwise:YES];
    p.y += ORC_RADIUS;
    p.x -= bw;
    [path addLineToPoint: p];
   
    p.x -= ORC_RADIUS/2;
    p.y += ORC_RADIUS;
    [path addLineToPoint: p];
    p.x -= ORC_RADIUS/2;
    p.y -= ORC_RADIUS;
    [path addLineToPoint: p];
    p.x -= bw;
    [path addLineToPoint: p];
    p.y -= ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1415926/2.0
                  endAngle:3.1415926
                 clockwise:YES];
    p.x -= ORC_RADIUS;
    p.y -= h;
    [path addLineToPoint: p];
    p.x += ORC_RADIUS;
    [path addArcWithCenter:p
                    radius:ORC_RADIUS
                startAngle:3.1415926
                  endAngle:3.1415926*1.5
                 clockwise:YES];
    [path closePath];
}
- (void) dealloc
{
    [label release];
    [title release];
    [path release];
    [super dealloc];
}
@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值