core-graphics

iOS: CGAffineTransformScale moves my object

依然范特西╮ 提交于 2019-12-02 23:24:37
Building on a question I had earlier . Simple button trying to transform a label. I want it to shrink by 0.5, which works but for some reason it also moves the object as it does it. The label jumps up and to the left, then transforms. - (IBAction)btnTest:(id)sender { [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ lblTest.transform = CGAffineTransformScale(lblTest.transform, 0.5f,0.5f); }completion:^(BOOL finished) { if(finished){ NSLog(@"DONE"); } }]; } I'm presuming from the question that you're using auto layout: In auto layout, if you have a

Turn two CGPoints into a CGRect

假装没事ソ 提交于 2019-12-02 22:21:31
How can I, given two different CGPoints , turn them into an CGRect ? Example: CGPoint p1 = CGPointMake(0,10); CGPoint p2 = CGPointMake(10,0); How can I turn this into a CGRect ? This will take two arbitrary points and give you the CGRect that has them as opposite corners. CGRect r = CGRectMake(MIN(p1.x, p2.x), MIN(p1.y, p2.y), fabs(p1.x - p2.x), fabs(p1.y - p2.y)); The smaller x value paired with the smaller y value will always be the origin of the rect (first two arguments). The absolute value of the difference between x values will be the width, and between y values the height. colinta A

How to draw an oval speech bubble programmatically on iPhone?

家住魔仙堡 提交于 2019-12-02 21:21:00
The technique shown in a similar question is a rectangular bubble. How to draw one in an oval shape? i.e.:     I would do it in two iterations. First get the context and begin a path. Fill an ellipse and then a custom path that encloses a triangle with three lines. I assumed the following dimensions: 70 width, 62 height. Override draw rect in a subclass of UIView and instantiate in a subclassed UIViewController: -(void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(ctx, 0.0, 0.0, 1.0, 1.0); CGContextFillEllipseInRect(ctx, CGRectMake(0.0, 0.0,

Core Text - Height of glyph

流过昼夜 提交于 2019-12-02 21:11:39
I have 2 attributed strings say 'A' and '.' I need to calculate the height of each of these strings. Currently the height returned is the same for both, it seems to return the maximum possible height for the tallest character in a given font (even if that character isn't present in the string). I would like to get the exact pixel height for each of these characters, so that I can resize a view around them that fits the character (glyph) snugly. I've tried using CTFramesetterSuggestFrameSizeWithConstraints() and CTLineGetTypographicBounds() but it returns a number similar to the attributed

UIGraphicsBeginImageContextWithOptions and Multithreading

纵然是瞬间 提交于 2019-12-02 21:04:51
I'm a bit confused about UIGraphicsBeginImageContextWithOptions and threading because according to UIKit Function Reference UIGraphicsBeginImageContextWithOptions should be called only on the main thread. When called it creates a bitmap-based context, which is ready to be manipulated either with CoreGraphics' functions or with methods like - drawInRect: for UIImage , -drawInRect:withFont: for NSString and so on. For CoreGraphics' drawing everything is clear - you pass a CGContextRef argument that is being manipulated to every function, but the UIKit drawing methods use the current context in

How do I check if CGContext contains point?

天大地大妈咪最大 提交于 2019-12-02 20:59:26
问题 Basically I have image that gets drawn when the touch is moved. When i toggle on a button called eraser I want it to detect if the context I have drawn is NOT black at the position the touch is at. Is there any way to do this? - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { hue = 0.0; [self initContext:frame.size]; framsize = frame.size; } return self; } -(void)clear{ cacheContext = nil; cacheBitmap = nil; [self initContext:framsize]; [self setNeedsDisplay]

Pie chart using Charts library with swift

蓝咒 提交于 2019-12-02 20:47:11
I am integrating pie chart in my app using Charts library and getting issue with chart data my code is import UIKit import Charts class ViewController: UIViewController { @IBOutlet weak var pieChartView: PieChartView! override func viewDidLoad() { super.viewDidLoad() let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] let unitsSold = [10.0, 4.0, 6.0, 3.0, 12.0, 16.0] setChart(dataPoints: months, values: unitsSold) } func setChart(dataPoints: [String], values: [Double]) { var dataEntries: [ChartDataEntry] = [] for i in 0..<dataPoints.count { let dataEntry1 = ChartDataEntry(x: Double(i), y:

UIGraphicsGetCurrentContext vs UIGraphicsBeginImageContext/UIGraphicsEndImageContext

纵饮孤独 提交于 2019-12-02 20:26:05
I am new to these parts of iOS API and here are some questions that are causing an infinite loop in my mind Why does ..BeginImageContext have a size but ..GetCurrentContext does not have a size? If ..GetCurrentContext does not have a size, where does it draw? What are the bounds? Why did they have to have two contexts, one for image and one for general graphics? Isn't an image context already a graphic context? What was the reason for the separation (I am trying to know what I don't know) daveMac UIGraphicsGetCurrentContext() returns a reference to the current graphics context. It doesn't

CAGradientLayer bounds not changing

戏子无情 提交于 2019-12-02 20:02:57
问题 I have a CAGradientLayer which is added to a UIVIew , when I rotate the device the view that it is added to increases in size (with autolayout) however the CA layer doesn't change its size. I have tried implementing the viewDidLayoutSubviews method and setting the layers frame in there but it doesn't make any difference. Once the device is rotated if I navigate away from the view and then back to it then the layer gets drawn correctly. 回答1: You could override - (void)layoutSubviews in your

Multiple Clipped Rects to Create Collage in Core Graphics

断了今生、忘了曾经 提交于 2019-12-02 19:48:06
I am creating a collage combined with elements from other images. Here is some ASCII art to explain what I am doing: Given images A, B and C, AAA, BBB, CCC AAA, BBB, CCC AAA, BBB, CCC I take part of A, part of B and part of C as columns: Axx, xBx, xxC Axx, xBx, xxC Axx, xBx, xxC ...and combine them in one image like this: ABC ABC ABC where the first 1/3rd of the image is a colum of A's pic, the middle is a column of B's pic and the last is a column of C's pic. I have some code written but it is only showing the first column and not the rest… I think I have to clear the clipping somehow, bt I