Posts

Showing posts with the label objective-c

How to display 3 cells per row in UICollectionView?

Image
Clash Royale CLAN TAG #URR8PPP How to display 3 cells per row in UICollectionView? I used a custom flow layout according to this post. Here is my implementation: @implementation CustomLayout -(void)prepareLayout{ [super prepareLayout]; // [self invalidateLayout]; if(self.collectionView){ CGSize newItemSize=self.itemSize; // Number of items per row int itemsPerRow=3; float totalSpacing=self.minimumLineSpacing*(itemsPerRow-1); newItemSize.width=(self.collectionView.bounds.size.width -totalSpacing)/itemsPerRow; if(self.itemSize.height>0){ float itemAspectRatio=self.itemSize.width/self.itemSize.height; newItemSize.height=newItemSize.width/itemAspectRatio; } [self setItemSize:newItemSize]; } } @end This is what I've got: What did I miss? I've come across some other SO posts but no luck so far. 4 Answers 4 Swift 3.0. Works for both horizontal and v...

How can I move the clear button in a UITextField?

Image
Clash Royale CLAN TAG #URR8PPP How can I move the clear button in a UITextField? For some reason, when I add a UITextfield as a subview of the contentview of a tablecell, the clearbutton does not align with the text typed in the field, and appears a bit underneath it. Is there any way I can move the text of the clearbutton to stop this from happening? Thanks for any help, 6 Answers 6 I haven't seen this, and a screen shot would be helpful. But, the quick answer is that you can inspect the subviews array of the UITextField, find the subview that contains the clear button, and adjust its frame.origin. Edit: It seems I've been downvoted for this answer (written in 2010). This is of not an "officially" approved method because you're manipulating private objects, but it's not detectable by Apple. The main risk is that the view hierarchy might be changed at some point. ...

Store and get UIColor from .plist file

Image
Clash Royale CLAN TAG #URR8PPP Store and get UIColor from .plist file I've been searching for this for a while now with no success. My question is: is there an easy way to store and get UIColors such as [UIColor blackColor] or [UIColor colorWithRed:0.38 green:0.757 blue:1 alpha:1]; in a .plist file in my app directory? [UIColor blackColor] [UIColor colorWithRed:0.38 green:0.757 blue:1 alpha:1]; 3 Answers 3 according to this discussion you have two options: NSData option NSData *theData = [NSKeyedArchiver archivedDataWithRootObject:[UIColor greenColor]]; NSString option NSString *color = @"greenColor"; [UIColor performSelector:NSSelectorFromString(color)] read more here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/27335-setting-uicolor-plist.html Thanks, helped me a lot – kopproduction Aug 30 '11 at 14:4...

Swipe gestures in WKWebView

Image
Clash Royale CLAN TAG #URR8PPP Swipe gestures in WKWebView So I have a WKWebView inside a UICollectionViewCell . I have to open few webpages but those webpages are eating up the scrolling by overriding touchmove event as below: WKWebView UICollectionViewCell touchmove document.addEventListener('touchmove', function(e) { e.preventDefault(); } I have tried adding swipe gestures to WKWebView and its superview . touchesMoved: is also not getting called inside superview. I cant disable userInteraction on webview as I want to be able to tap and interact with webview. WKWebView superview touchesMoved: userInteraction I tried overriding the existing touchmove event of webpage by injecting script: touchmove WKUserScript *script = [[WKUserScript alloc]initWithSource:@"window.ontouchmove = function() { window.webkit.messageHandlers.touchmoved.postMessage('Touches Moved..'); return true; ...

Understanding of 'true' and '@1', is this a same?

Image
Clash Royale CLAN TAG #URR8PPP Understanding of 'true' and '@1', is this a same? I try to understand something in Obj-C: I read this Q-A but still I don't understand following use case: we know that: #define YES ((BOOL)1) #define NO ((BOOL)0) I try to store boolean value into dictionary: Case 1: json[@"key"] = @NO; or json[@"key"] = @YES; Case 2: BOOL isSomeFlag = /* ... */ json[@"key"] = @(!isSomeFlag); or: json[@"key"] = @(isSomeFlag); so I get different results: in 1st case true or false , in 2nd case: @0 or @1 true false @0 @1 is this the same? a.e. @0 = false ? @0 false Do I need to cast to BOOL like: json[@"key"] = @((BOOL)!isSomeFlag); to get the same results? BOOL json[@"key"] = @((BOOL)!isSomeFlag); Thanks, Litterals, they are just short code. clang.llvm.org/docs/ObjectiveCLiterals.html – WrightsCS 2 mins ago ...