先上代码
+ (MeetTableViewCell *)cellFromNib
{
MeetTableViewCell *cell = [[[NSBundlemainBundle]loadNibNamed:@"MeetTableViewCell"owner:selfoptions:nil]objectAtIndex:0];
return cell;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
self=[superinitWithCoder:aDecoder];
if (self) {
self = [[[NSBundlemainBundle]loadNibNamed:@"MeetTableViewCell"owner:selfoptions:nil]objectAtIndex:0];
}
return self;
}
和自定义xib用什么方法初始化
- (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageView=[[UIImageView alloc] initWithFrame:self.view.frame]; [self.view addSubview:imageView]; self.view.backgroundColor=[UIColor blueColor]; UIGraphicsBeginImageContext(imageView.frame.size); [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0); //线宽 CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); //颜色 CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 100, 100); //起点坐标 CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 200, 100); //终点坐标 CGContextStrokePath(UIGraphicsGetCurrentContext()); imageView.image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } ‘
自己写的在button上绘制两个圆
UIImageView *imageView1=[[UIImageView alloc] initWithFrame:CGRectMake(0 , 0, kCircleDiameter, kCircleDiameter)];
UIGraphicsBeginImageContext(imageView1.frame.size);
[imageView1.image drawInRect:CGRectMake(0, 0, button.frame.size.width, button.frame.size.height)];
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0,0,0,1.0);//画笔线的颜色
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1.0);//线的宽度
CGContextAddArc(UIGraphicsGetCurrentContext(), kCircleDiameter/2, kCircleDiameter/2, kCircleDiameter/2-5, 0, 2*PI, 0);
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathStroke);
CGContextAddArc(UIGraphicsGetCurrentContext(), kCircleDiameter/2, kCircleDiameter/2, kCircleDiameter/4, 0, 2*PI, 0);
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathFill);
imageView1.image=UIGraphicsGetImageFromCurrentImageContext();
[button setBackgroundImage:imageView1.image forState:UIControlStateSelected];
![]()