cgrect

Aspect fit programmatically in iOS?

跟風遠走 提交于 2019-11-28 10:54:38
问题 I want to insert one view into another with aspect fit option. But I can't just set contentMode for some reasons. Could you provide a solution via resizing of the inner CGRect according to the outer CGRect ? And yes, there are a lot of similar questions but no one provides such solution. 回答1: I wrote a function that should achieve what you desire. It will return the CGRect of a given innerRect , after scaling it to fit within a given outerRect , while maintaining aspect ratio. The innerRect

Can I adjust a CGRect with a UIEdgeInsets?

假装没事ソ 提交于 2019-11-28 06:12:16
I've got a CGRect , and I'd like to adjust it with a UIEdgeInsets . It seems like perhaps there might be a built in function that does this. I've looked for a CGRectAdjustByInsets or functions with some other CGRect… prefix, but I didn't find anything. Should I code my own? TL;DR Swift 4.2 use theRect.inset(by: theInsets) . Objective c use UIEdgeInsetsInsetRect(theRect, theInsets) Example // CGRectMake takes: left, bottom, width, height. const CGRect originalRect = CGRectMake(0, 0, 100, 50); // UIEdgeInsetsMake takes: top, left, bottom, right. const UIEdgeInsets insets = UIEdgeInsetsMake(10,

Objective-c: How to rotate CGRect

拜拜、爱过 提交于 2019-11-28 04:01:51
问题 I've tried to rotate my rectangle, but it does not work properly. Here is part of my code, I found it in another post: #define DEGREES_TO_RADIANS(x) (M_PI * x / 180.0) -(void)drawRect:(NSRect)rect { CGContextRef cRef = [[NSGraphicsContext currentContext] graphicsPort]; // points[] - this is a CGPoints array, length_one is a double value CGRect rect_one = CGRectMake(points[0].x, points[0].y, (CGFloat)length_one, 40); // I've print out the origin of old one and new one NSLog(@"old rect -- %f,

can a particular rect of UIview have different alpha..?

[亡魂溺海] 提交于 2019-11-27 20:51:33
问题 I wan't a imageview which is semi-transparent in other parts and completely transparent in the middle .. see this image.. i have managed to do it but it is not the best of ways.. can I only have a rect inside yellow lines transparent ...? EDIT : Is it possible to change the alpha of a certain rect of a view..? 回答1: Place a custom UIView over the view showing the image, size and position it to exactly overlap. In the custom view's drawRect method - (void)drawRect:(CGRect)rect { // Drawing code

Can I adjust a CGRect with a UIEdgeInsets?

帅比萌擦擦* 提交于 2019-11-27 19:17:39
问题 I've got a CGRect , and I'd like to adjust it with a UIEdgeInsets . It seems like perhaps there might be a built in function that does this. I've looked for a CGRectAdjustByInsets or functions with some other CGRect… prefix, but I didn't find anything. Should I code my own? 回答1: TL;DR Swift 4.2 use theRect.inset(by: theInsets). Objective c use UIEdgeInsetsInsetRect(theRect, theInsets) Example // CGRectMake takes: left, bottom, width, height. const CGRect originalRect = CGRectMake(0, 0, 100,

“Expression is not assignable” — Problem assigning float as sum of two other floats in xCode?

£可爱£侵袭症+ 提交于 2019-11-27 04:10:48
In a piano app, I'm assigning the coordinates of the black keys. Here is the line of code causing the error. 'blackKey' and 'whiteKey' are both customViews blackKey.center.x = (whiteKey.frame.origin.x + whiteKey.frame.size.width); The other answers don't exactly explain what's going on here, so this is the basic problem: When you write blackKey.center.x , the blackKey.center and center.x both look like struct member accesses, but they're actually completely different things. blackKey.center is a property access, which desugars to something like [blackKey center] , which in turn desugars to