Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CircleView.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b91d883292217f47833ec4666547a4d7c0fba5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#import <UIKit/UIKit.h>
#import "CircleView.h"
#import <QuartzCore/QuartzCore.h>

@interface CircleView()

@property (nonatomic) UIColor * circleColor;

@end

@implementation CircleView

- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color
{
  self = [super initWithFrame:frame];
  if (self)
  {
    self.circleColor = color;
    self.opaque = NO;
  }
  return self;
}

- (void)drawRect:(CGRect)rect
{
  CGContextRef ctx = UIGraphicsGetCurrentContext();
  CGContextAddEllipseInRect(ctx, rect);
  CGContextSetFillColor(ctx, CGColorGetComponents([self.circleColor CGColor]));
  CGContextFillPath(ctx);
}

+ (UIView *)createViewWithCircleDiameter:(CGFloat)diameter andColor:(UIColor *)color
{
  UIView * circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, diameter, diameter)];
  circleView.backgroundColor = [UIColor clearColor];
  CircleView * circle = [[CircleView alloc] initWithFrame:CGRectMake(0.5, 0.5, diameter - 1, diameter - 1) andColor:color];
  [circleView addSubview:circle];
  return circleView;
}

+ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color
{
  UIView * circle = [self createViewWithCircleDiameter:diameter andColor:color];
  return [self imageWithView:circle];
}

+ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color andSubview:(UIView *)view
{
  UIView * circle = [self createViewWithCircleDiameter:diameter andColor:color];
  [circle addSubview:view];
  return [self imageWithView:circle];
}


+ (UIImage *)imageWithView:(UIView *)view
{
  UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
  [view.layer renderInContext:UIGraphicsGetCurrentContext()];

  UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  return img;
}

@end