This question was originally asked for the objective-c programming language. At the time of writing, swift didn't even exist yet.
self.frame.size.width = 50;
self.frame = CGRectMake(self.frame.origin.x,
margin: 5px 5px 5px 2px;
To answer your original question: yes, it's possible to change just one member of a
CGRect structure. This code throws no errors:
myRect.size.width = 50;
What is not possible, however, is to change a single member of a
CGRect that is itself a property of another object. In that very common case, you would have to use a temporary local variable:
CGRect frameRect = self.frame; frameRect.size.width = 50; self.frame = frameRect;
The reason for this is that using the property accessor
self.frame = ... is equivalent to
[self setFrame:...] and this accessor always expects an entire
CGRect. Mixing C-style
struct access with Objective-C property dot notation does not work well in this case.