Posts

Showing posts with the label Objective C

Auto Layout: Y Position As The Max Of Two Values

Image
Answer : Here's one way to think about it: create a constraint that the top of playButton is greater than or equal to the bottom of myView1 plus 10, another constraint that the top of playButton is greater than or equal to the bottom of myView2 plus 10, and then a third constraint that the top of playButton be at the top of the shared superview at a low priority. The two inequalities will make sure the button is below the two views. However, that leaves ambiguity. The button could be anywhere below both. The third constraint can't be satisfied as such, but the auto layout system will try to get as close as possible. This resolves the ambiguity. The button will be as close to the top as possible while still being below both views. This can actually be simplified. You could sort of combine one of the inequalities with the low-priority equality. Have one constraint that the top of playButton is greater than or equal to the bottom of myView1 plus 10. Have a second constrain...

Adding Custom Fonts To IOS App Finding Their Real Names

Image
Answer : Use +[UIFont familyNames] to list all of the font family names known to the system. For each family name, you can then use +[UIFont fontNamesForFamilyName:] to list all of the font names known to the system. Try printing those out to see what name the system expects. Example code: static void dumpAllFonts() { for (NSString *familyName in [UIFont familyNames]) { for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"%@", fontName); } } } Put that in your app, call it, and see what you get. If you see a name in the output that looks appropriate for your font, use it. Otherwise, perhaps you haven't properly added the font to your app. In swift 4.2+ use code given below: func dumpAllFonts() { for familyName in UIFont.familyNames { for fontName in UIFont.fontNames(forFamilyName: familyName) { print("\(fontName)") } } } ...

Add Views In UIStackView Programmatically

Image
Answer : Stack views use intrinsic content size, so use layout constraints to define the dimensions of the views. There is an easy way to add constraints quickly (example): [view1.heightAnchor constraintEqualToConstant:100].active = true; Complete Code: - (void) setup { //View 1 UIView *view1 = [[UIView alloc] init]; view1.backgroundColor = [UIColor blueColor]; [view1.heightAnchor constraintEqualToConstant:100].active = true; [view1.widthAnchor constraintEqualToConstant:120].active = true; //View 2 UIView *view2 = [[UIView alloc] init]; view2.backgroundColor = [UIColor greenColor]; [view2.heightAnchor constraintEqualToConstant:100].active = true; [view2.widthAnchor constraintEqualToConstant:70].active = true; //View 3 UIView *view3 = [[UIView alloc] init]; view3.backgroundColor = [UIColor magentaColor]; [view3.heightAnchor constraintEqualToConstant:100].active = true; [view3.widthAnchor constraintEqualToConstant...

Capture Redirect Url In Wkwebview In Ios

Answer : Use this WKNavigationDelegate method public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) { if(navigationAction.navigationType == .other) { if navigationAction.request.url != nil { //do what you need with url //self.delegate?.openURL(url: navigationAction.request.url!) } decisionHandler(.cancel) return } decisionHandler(.allow) } Hope this helps (This answers the slightly more general question of how to detect a URL redirection in WKWebView, which is the search that lead me to this page.) Short answer Use WKNavigationDelegate 's webView(_:didReceiveServerRedirectForProvisionalNavigation:) function and examine WKWebView 's URL property. Longer answer There are a couple of places you could detect a server-side redirect. On iOS 10.3...