Questions tagged [cgrect]

CGRect is a structure from the ApplicationServices framework used with Apple's OSX and iOS operating systems. This structure is used to represent the origin and size of a rectangle.

CGRect is a structure that contains the location and dimensions of a rectangle.

Fields

  • origin: A point that specifies the coordinates of the rectangle’s origin.
  • size: A size that specifies the height and width of the rectangle.
716 questions
20
votes
1 answer

MonoTouch: Where is Frame.Origin?

I am trying to translate this centering code snip in Objective-C into MonoTouch imageView.frame.origin.x = CGRectGetMidX(view.bounds) - CGRectGetMidX(imageView.bounds) But can't find where Origin is.
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
20
votes
2 answers

Difference between CGSize and CGRect

What is the difference between CGSize and CGRect? As a beginner reading the CGGeometry Reference it wasn't immediately obvious, especially because there were references to size being a vector. I was kind of surprised that I couldn't find this basic…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
16
votes
1 answer

How to get coordinates (CGRect) for the selected text in UIWebView?

I have simple UIWebView with loaded html. I want to show the PopoverView pointed to the selected text. I can get the menuFrame of the UIMenuController and use its rect, but the result isn't as accurate at the corners of the screen as I need. I can…
adnako
  • 1,287
  • 2
  • 20
  • 30
16
votes
3 answers

Subtract CGRect from CGRect -- largest piece of one not containing the other

How I can substract one CGRect from another? I want the result R1 - R2 to be the largest subrectangle of R1 that does not intersect R2. Example 1: +----------------------------------+ | +--------+ | | | R2 | …
anonymous
  • 163
  • 1
  • 1
  • 5
16
votes
3 answers

Create CGRect with short way - swift

When I created CGRect in Objective-c and I didn't want to set each value, I created in this way: (CGRect){CGPointMake(0, 0), [UIScreen mainScreen].bounds.size} Do you know a similar way in swift?
xarly
  • 2,054
  • 4
  • 24
  • 40
16
votes
1 answer

Better to use CGRectGetHeight(view.bounds) or view.bounds.size.height directly in Objective-C

I can't find where I read it, but I remember coming across something that suggested it is better to access height of CGRects using CGRectGetHeight(rect) instead of accessing the variable via rect.size.height CGFloat height =…
Logan
  • 52,262
  • 20
  • 99
  • 128
15
votes
5 answers

How to resize UITextView while typing inside it?

I'm creating a comment section much like the one Facebook uses for it's messaging section in it's iOS app. I want the UITextView to resize the height so the text I'm typing fits inside it rather than you having to scroll to see the text that…
Ollie177
  • 315
  • 1
  • 3
  • 17
14
votes
1 answer

Converting a CGRect to an NSValue in an Array and vice versa

I have an array, full of CGRects. That part is fine. The problem is when I go to retrieve the CGRects from the array, I'm getting weird errors. Check out my code. NSArray *frameLocations = [NSArray arrayWithObjects: …
Andrew
  • 3,874
  • 5
  • 39
  • 67
14
votes
3 answers

Difference between frame.size.width and frame.width

I was writing a program in swift and just now I noticed that I can directly access a CGRect frame's width and height properties directly without using the CGSize width and height. That is I am now able to write a code like this. @IBOutlet var…
Harikrishnan
  • 7,765
  • 13
  • 62
  • 113
14
votes
5 answers

Can any one please explain what is use of CGRectZero

I am new to iOS. Can any one please explain what the use is of CGRectZero and where it is used?
Siva
  • 181
  • 1
  • 1
  • 6
13
votes
4 answers

Split a rectangle into equal sized rectangles?

I need to split a rectangle (A CGRect structure which is {{float x,float y},{float w,float h}}) into a number of smaller rectangles/structures, creating some sort of a grid. I'm writing a window layout manager and I want a window preview option. I…
Kristina
  • 15,859
  • 29
  • 111
  • 181
13
votes
4 answers

UIView height is not right on iPhone 5

I am migrating my apps over and on one I use a UIPickerView. In the viewDidLoad method I create the picker and set it's y origin to be self.view.frame.size.height so that it is off screen. Then I just move it up when needed. On the iPhone 5…
random
  • 8,568
  • 12
  • 50
  • 85
12
votes
7 answers

Getting CGRect from array

For my application I am trying to store CGRect objects into an NSMutableArray. It is loading well and printing in the log statement, but trying to take the CGRects from the array shows an error. Here is a code snippet: CGRect lineRact =…
ajay
  • 3,245
  • 4
  • 31
  • 59
12
votes
6 answers

Set background color for only part of UIView

I want the bottom (not quite half) of my UIView to be a different color than the top. I'm wondering if I should create a CGRect and then color that? Is this along the right track? - (void)drawRect:(CGRect)rect { CGRect aRect = CGRectMake(x, y,…
AllieCat
  • 3,890
  • 10
  • 31
  • 45
12
votes
1 answer

Cannot get current position of CALayer during animation

I am trying to achieve an animation that when you hold down a button it animates a block down, and when you release, it animates it back up to the original position, but I cannot obtain the current position of the animating block no matter what.…
Matt
  • 2,920
  • 6
  • 23
  • 33
1
2
3
47 48