Reputation: 177
I have been trying to use cgsizemake
as follows:
I'm trying to make the frame of my image a different size using cgrectmake
instead of changing the coordinates.
So far I have tried
maincharacter.frame = cgsizemake (14, 14);
but I keep getting the error
assigning to cgrect from incompatible type CGsize
Upvotes: 15
Views: 41759
Reputation: 5754
CGSize only accepts height and width
CGSize c=CGSizeMake(width, height);
If you want to set the frame size use CGRectMake
maincharacter.frame=CGRectMake(x-origin,y-origin, width, height);
Upvotes: 14
Reputation: 1133
below is an example of using CGSizeMake in a UIScrollView
var mainScrollView: UIScrollView?
var numPages = 3
override func viewDidLoad() {
super.viewDidLoad()
//this gets the screen frames size
var fm: CGRect = UIScreen.mainScreen().bounds
//creates a UIScrollView programmatically
self.mainScrollView = UIScrollView(frame:CGRectMake(0, 0, fm.size.width, fm.size.height))
self.mainScrollView!.contentSize = CGSizeMake(self.mainScrollView!.frame.size.width, self.mainScrollView!.frame.size.height * CGFloat(numPages))
}
Upvotes: 0
Reputation: 2253
CGSize viewwidth;
viewwidth=[[UIScreen mainScreen] bounds].size;
this will help you to get device current resolution using cgsize.
viewwidth.width or viewwidth.height
as above u can use it. and also as below code
rightslide=[[UIView alloc]initWithFrame:CGRectMake(0,0, viewwidth.width, viewwidth.height)];
Upvotes: 0
Reputation: 2634
To use the variable c
which is of type CGSize
you would call c.0
and c.1
for the height and width respectively. I don't know why they named those properties 0 and 1 but you will have to take that up with Dennis Ritchie
Here is an example usage of CGSizeMake
:
var makeSize = CGSizeMake(size.0, size.1)
let circ = SKShapeNode(ellipseOfSize: makeSize)
Hope that helps.
Upvotes: 0
Reputation: 36
maincharacter.frame must return (x, y, width, height) 4 parameters and CGSizeMake only have "width" and "height" 2 parameters. So You got an error. The solution is use frame.size, which returns 2 parameters to work with CGSizeMake(14, 14).
Upvotes: 1
Reputation: 318824
One solution would be:
CGRect frame = maincharacter.frame;
frame.size = CGSizeMake(14, 14);
maincharacter.frame = frame;
Upvotes: 19