cgsize

Distance between two rectangles

北慕城南 提交于 2020-01-13 19:09:03
问题 How can I find the distance between two rectangles? Intersects should return 0 in distance. 回答1: Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin

Difference between frame.size.width and frame.width

梦想的初衷 提交于 2019-12-29 06:45:07
问题 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 myView: UIView! override func viewDidLoad() { super.viewDidLoad() var height = myView.frame.height var height1 = myView.frame.size.height } In Objective C, when I tried to write the same code, the line height = view.frame.height is throwing an error. Can

How to compute the frame of a UIView before the transform?

女生的网名这么多〃 提交于 2019-12-23 17:43:03
问题 Question I have a UIView and I apply to it a CGAffineTransform . I would like to be able to know the frame of the view if the transform had not be applied . I am looking for a (simple) solution that handles the case where the transform is the "zero-transform" (which is not invertible). My attempt The following does not work for the "zero-transform", I guess. CGRect result ; CGAffineTransform transform = self.transform ; result = CGRectApplyAffineTransform(self.frame, CGAffineTransformInvert

Get the NSString height in iOS 7 [duplicate]

巧了我就是萌 提交于 2019-12-22 06:46:13
问题 This question already has answers here : Replacement for deprecated sizeWithFont: in iOS 7? (20 answers) Closed 5 years ago . I am using the below code to calculate the height of a label from string length. Im using xcode 5.0 and it works fine in iOS 6 simulator but it's not working well in iOS 7. NSString* str = [[array objectAtIndex:i]valueForKey:@"comment"]; CGSize size = [className sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode

iOS Swift - CGSizeFromString throws CGSizeZero

两盒软妹~` 提交于 2019-12-12 04:55:58
问题 I have this function which is used to set size from String length. Something like that - Swift iOS - Tag collection view. First item in categoriesItems is "Age" func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { var cellWidth : CGSize = CGSizeFromString(self.categoriesItems[indexPath.row].name); return cellWidth } 回答1: To determine the width of text use the following code let

OCMock passing any CGSize

给你一囗甜甜゛ 提交于 2019-12-11 13:15:08
问题 I'm using OCMock and I'm trying to do to something like this in one of my tests: [[mockScrollView expect] setContentSize:[OCMArg any]]; The problem is that [OCMArg any] returns an id type, and I want to use any CGSize , because I don't know it's exact value. How can I pass this argument? 回答1: With version 2.2 of OCMock you can use ignoringNonObjectArgs [[mockScrollView expect] ignoringNonObjectArgs] setContentSize:dummySize]; 回答2: AFAIK there is no way to accomplish that with OCMock. An

Distance between two rectangles

杀马特。学长 韩版系。学妹 提交于 2019-12-06 13:13:40
How can I find the distance between two rectangles? Intersects should return 0 in distance. Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin.x == mostRight.origin.x ? 0 : mostRight.origin.x - (mostLeft.origin.x + mostLeft.size.width); xDifference =

Get the NSString height in iOS 7 [duplicate]

我的梦境 提交于 2019-12-05 09:52:11
This question already has an answer here: Replacement for deprecated sizeWithFont: in iOS 7? 20 answers I am using the below code to calculate the height of a label from string length. Im using xcode 5.0 and it works fine in iOS 6 simulator but it's not working well in iOS 7. NSString* str = [[array objectAtIndex:i]valueForKey:@"comment"]; CGSize size = [className sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; Height_1 = size.height; If there is any solution for iOS 7 then please help. Thanks in Advance Well here is

Faster way to estimate cell height in a CollectionView

可紊 提交于 2019-12-05 06:09:34
问题 I have an infinite scroll in my UICollectionView and I've noticed that the way I estimate my cell height is the bottleneck of my collection view. It causes some long delays the more I scroll my collection view. Is there a better way to estimate the heights of my cells? The cells have different heights because I have a UILabel in each of them. I assign a NSMutableAttributedStrings of different lengths to those UILabels: let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment =

Faster way to estimate cell height in a CollectionView

老子叫甜甜 提交于 2019-12-03 20:36:35
I have an infinite scroll in my UICollectionView and I've noticed that the way I estimate my cell height is the bottleneck of my collection view. It causes some long delays the more I scroll my collection view. Is there a better way to estimate the heights of my cells? The cells have different heights because I have a UILabel in each of them. I assign a NSMutableAttributedStrings of different lengths to those UILabels: let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .justified paragraphStyle.lineSpacing = 5.0 let attributedText = NSMutableAttributedString(string: " \