//
// san.m
// san
//
// Created by baipeng on 2017/6/12.
// Copyright ? 2017年 BPG. All rights reserved.
//
import "san.h"
@implementation san
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIView *bac = [[UIView alloc]initWithFrame:[self menuFrame]];
bac.backgroundColor = [UIColor whiteColor];
bac.layer.masksToBounds = YES;
bac.layer.cornerRadius = 4.0;
[self addSubview:bac];
}
return self;
} - (CGRect)menuFrame {
CGFloat menuX = [UIScreen mainScreen].bounds.size.width - 180;
CGFloat menuY = 60;
CGFloat width = 150;
CGFloat heigh = 40 * 6;
return (CGRect){menuX,menuY,width,heigh};
}
pragma mark 繪制三角形
- (void)drawRect:(CGRect)rect
{
// 設(shè)置背景色
[[UIColor whiteColor] set];
//拿到當(dāng)前視圖準(zhǔn)備好的畫板
CGContextRef context = UIGraphicsGetCurrentContext();
//利用path進(jìn)行繪制三角形
CGContextBeginPath(context);//標(biāo)記
CGFloat location = self.frame.size.width - 30 - 10 - 10;
CGContextMoveToPoint(context,
location+8, 50);//設(shè)置起點 上點
CGContextAddLineToPoint(context,
location , 60);//左側(cè)
CGContextAddLineToPoint(context,
location + 16, 60);//右側(cè)
CGContextClosePath(context);//路徑結(jié)束標(biāo)志,不寫默認(rèn)封閉
[[UIColor whiteColor] setFill]; //設(shè)置填充色
[[UIColor whiteColor] setStroke]; //設(shè)置邊框顏色
CGContextDrawPath(context,
kCGPathFillStroke);//繪制路徑path
}
@end