working on it ...

Filters

Explore Public Snippets

Sort by

Found 12 snippets matching: uitoolbar

    public by WadeCantley modified Dec 9, 2014  4690219  56  7  0

    iOS - Swift - Add a Done button to a Keyboard Tool Bar

    Adding a done button to the keyboard tool bar and working within the textField delegate to make that happen. In this situation the keyboard is a number pad which doesn't have its own done button.
    //MARK: - Helper Methods
        
    // This is called to remove the first responder for the text field.
    func resign() {
        self.resignFirstResponder()
    }
        
    // This triggers the textFieldDidEndEditing method that has the textField within it.  
    //  This then triggers the resign() method to remove the keyboard.
    //  We use this in the "done" button action.
    func endEditingNow(){
        self.view.endEditing(true)
    }
        
        
    //MARK: - Delegate Methods
        
    // When clicking on the field, use this method.
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
    
            
        // Create a button bar for the number pad
        let keyboardDoneButtonView = UIToolbar()
        keyboardDoneButtonView.sizeToFit()
            
        // Setup the buttons to be put in the system.
        let item = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: Selector("endEditingNow") )
        var toolbarButtons = [item]
            
        //Put the buttons into the ToolBar and display the tool bar
        keyboardDoneButtonView.setItems(toolbarButtons, animated: false)
        textField.inputAccessoryView = keyboardDoneButtonView
    
        return true
    }
        
    // What to do when a user finishes editting
    func textFieldDidEndEditing(textField: UITextField) {
            
        //nothing fancy here, just trigger the resign() method to close the keyboard.
        resign()
    }
        
        
    // Clicking away from the keyboard will remove the keyboard.
    override func touchesBegan(touches: (NSSet!), withEvent event: (UIEvent!)) {
        self.view.endEditing(true)
    }
        
    // called when 'return' key pressed. return NO to ignore.
    // Requires having the text fields using the view controller as the delegate.
    func textFieldShouldReturn(textField: UITextField!) -> Bool {
            
        // Sends the keyboard away when pressing the "done" button
        resign()
        return true
            
    }
    
    

    external by Panaminion modified Jul 29, 2014  8150  1  5  1

    [Swift] UIToolbar with Button

    [Swift] UIToolbar with Button: toolbar.swift
    let plusButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: nil, action: nil)
    var toolbarButtons = [plusButton];
    
    let toolbar = UIToolbar()
    toolbar.sizeToFit()
    toolbar.setItems(toolbarButtons, animated: true)
    toolbar.backgroundColor = UIColor.whiteColor()
    
    

    external by Mohamed Saleh Zaied modified Dec 23, 2015  79  0  1  0

    Make UIToolBar transparent

    Make UIToolBar transparent: gistfile1.txt
    if ([self.shareFooterToolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
        [self.shareFooterToolBar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    }
    if ([self.shareFooterToolBar respondsToSelector:@selector(setShadowImage:forToolbarPosition:)]) {
        [self.shareFooterToolBar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];
    }
    
    
    

    external by yar1vn modified Feb 8, 2015  57  0  1  0

    UIButton for UIToolbar

    UIButton for UIToolbar: gistfile1.txt
    //
    //  Button_.swift
    //  Crime Mapping
    //
    //  Created by Yariv on 1/23/15.
    //  Copyright (c) 2015 The Omega Group. All rights reserved.
    //
    
    import UIKit
    
    class UIButton_: UIButton {
      
      override func tintColorDidChange() {
        
        if let tintColor = tintColor {
          let normalImage = imageForState(.Normal)?.imageWithTint(tintColor, alpha: 0.3)
          let selectedImage = imageForState(.Selected)?.imageWithTint(tintColor, alpha: 0.3)
          
          // Make the button look like a UIBarButtonItem when highlighted
          setImage(normalImage, forState: .Normal | .Highlighted)
          setImage(selectedImage, forState: .Selected | .Highlighted)
        }
      }
    }
    
    private extension UIImage {
      
      func imageWithTint(color: UIColor, alpha: CGFloat) -> UIImage {
        let image = self.imageWithRenderingMode(.AlwaysTemplate)
        
        UIGraphicsBeginImageContextWithOptions(size, false, 0)
        color.setFill()
        UIBezierPath(rect: CGRect(origin: CGPointZero, size: size)).fill()
        image.drawAtPoint(CGPointZero, blendMode: kCGBlendModeDestinationIn, alpha: alpha)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return newImage
      }
    }
    
    
    

    external by colinta modified Apr 22, 2015  22  0  1  0

    example of a UIToolbar

    example of a UIToolbar: gistfile1.rb
    class AppDelegate
      def application(application, didFinishLaunchingWithOptions:launchOptions)
        rootViewController = ToolbarController.alloc.init
        rootViewController.title = 'toolbar'
        rootViewController.view.backgroundColor = UIColor.whiteColor
    
        navigationController = UINavigationController.alloc.initWithRootViewController(rootViewController)
    
        @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
        @window.rootViewController = navigationController
        @window.makeKeyAndVisible
    
        true
      end
    end
    
    
    class ToolbarController < UIViewController
    
      def loadView
        @layout = ToolbarLayout.new
        self.view = @layout.view
      end
    
    end
    
    
    class ToolbarLayout < MK::Layout
    
      def layout
        add UIToolbar, :toolbar
      end
    
      def toolbar_style
        frame from_bottom(height: 100, width: '100%')
        autoresizing_mask :fill_bottom
    
        items [
          UIBarButtonItem.alloc.initWithTitle(
            "Hello",
            style: UIBarButtonItemStylePlain,
            target: self,
            action: 'hello_pressed:'
          ),
          UIBarButtonItem.alloc.initWithBarButtonSystemItem(
            UIBarButtonSystemItemFlexibleSpace,
            target: nil,
            action: nil
          ),
          UIBarButtonItem.alloc.initWithBarButtonSystemItem(
            UIBarButtonSystemItemAction,
            target: self,
            action: 'hello_pressed:'
          )
        ]
      end
    
      def hello_pressed(sender)
        puts("hello")
      end
    
    end
    
    
    

    external by lluisgerard modified Jan 14, 2014  504  0  3  0

    iOS :: Know if a device is capable of doing iOS7 blur effect (using UIToolBar hack) Using: https://github.com/lmirosevic/GBDeviceInfo

    iOS :: Know if a device is capable of doing iOS7 blur effect (using UIToolBar hack) Using: https://github.com/lmirosevic/GBDeviceInfo: gistfile1.m
    + (BOOL)allowsBlurEffect {
    
        // I assume that any device that is not checked here is newer and therefore is "blur" capable
        static BOOL isAllowed = YES;
    
        static BOOL isChecked = NO;
        if (!isChecked) {
            
            isChecked = YES;
            
            GBDeviceDetails *deviceDetails = [GBDeviceInfo deviceDetails];
            
            // iOS 7 at least
            isAllowed = (deviceDetails.majoriOSVersion >= 7);
            if (isAllowed) {
                
                // If we have minimum iOS, now check the device
                switch (deviceDetails.family) {
                    case GBDeviceFamilyiPhone:
                        
                        // iPhone -- 4S at least
                        isAllowed = deviceDetails.majorModelNumber >= 4;
                        
                        break;
                        
                    case GBDeviceFamilyiPod:
                        
                        // iPod --- 5 Gen at least
                        isAllowed = deviceDetails.majorModelNumber >= 5;
                        
                        break;
                        
                    case GBDeviceFamilyiPad:
                        
                        // iPad ---- At least 4
                        isAllowed = deviceDetails.majorModelNumber >= 4;
    
                        // Maybe is an iPad mini and it is allowed
                        if (!isAllowed)
                            isAllowed = deviceDetails.model == (GBDeviceModeliPadMini | GBDeviceModeliPadMiniRetina);
                        
                    default:
                        break;
                }
            }
         
            NSLog(@"Device %@ blur effect", isAllowed ? @"ALLOWS" : @"DON'T ALLOWS");
        
        }
        
        return isAllowed;
        
    }
    
    
    

    external by Eric Rowe modified Aug 2, 2014  434  0  3  0

    Hiding the navigationBar and UIToolbar in Swift

    Hiding the navigationBar and UIToolbar in Swift: gistfile1.swift
    // in viewDidLoad...
            var tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "showToolbars")
            tapGestureRecognizer.cancelsTouchesInView = false
            scrollView.addGestureRecognizer(tapGestureRecognizer)
    
    // somewhere else...
        func showToolbars() {
            UIView.animateWithDuration(1.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
                self.toolbar.frame = CGRectMake(0, self.view.frame.size.height-self.toolbar.frame.size.height, self.toolbar.frame.size.width, self.toolbar.frame.size.height)
                if self.ios7Patches!.verticalSizeClass == UIUserInterfaceSizeClass.Compact { // iPhone Horizontal
                    self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)
                } else {
                    self.navigationController.navigationBar.frame = CGRectMake(0, 20, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)
                }
                }, completion: {(value: Bool) in})
            hideToolbarsTimer?.invalidate()
            hideToolbarsTimer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "hideToolbars", userInfo: nil, repeats: false)
        }
        func hideToolbars() {
            hideToolbars(nil, delay: nil)
        }
        func hideToolbars(duration:NSTimeInterval?, delay:NSTimeInterval?) {
            var intDelay : NSTimeInterval
            if var thisDelay = delay {
                intDelay = thisDelay
            } else {
                intDelay = 0.0
            }
            var intDuration : NSTimeInterval
            if var thisDuration = duration {
                intDuration = thisDuration
            } else {
                intDuration = 1.0
            }
            UIView.animateWithDuration(intDuration, delay: intDelay, options: UIViewAnimationOptions.CurveEaseOut, animations: {
                self.toolbar.frame = CGRectMake(0, self.view.frame.size.height, self.toolbar.frame.size.width, self.toolbar.frame.size.height)
                self.navigationController.navigationBar.frame = CGRectMake(0, -(self.navigationController.navigationBar.frame.size.height), self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)
                }, completion: {(value: Bool) in})
        }
    
    
    

    external by Github modified May 14, 2015  335  0  3  0

    UIToolBar に配置するボタンを等間隔に置きたい。

    UIToolBar に配置するボタンを等間隔に置きたい。: iOSFlexibleSpace.m
    - (NSArray*)toolBarItemsWithEdit:(BOOL)isEdit
    {
      // 等間隔に置くための Flexible Space
      UIBarButtonItem *fixItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                               target:nil
                                                                               action:nil];
      
      // UIButton 1
      UIBarButtonItem *firstItem = [[UIBarButtonItem alloc] initWithTitle:title
                                                                    style:UIBarButtonItemSystemBordered
                                                                   target:self
                                                                   action:@selector(touchUpInsideFirstItem:)];
      // UIButton 2
      UIBarButtonItem *secondItem = [[UIBarButtonItem alloc] initWithTitle:title
                                                                     style:UIBarButtonItemSystemBordered
                                                                    target:self
                                                                    action:@selector(touchUpInsideSecondItem:)];
      // UIButton 3
      UIBarButtonItem *thirdItem = [[UIBarButtonItem alloc] initWithTitle:title
                                                                    style:UIBarButtonItemSystemBordered
                                                                   target:self
                                                                   action:@selector(touchUpInsideThirdItem:)];
    }
    
    
    

    external by doluvor modified Oct 17, 2016  137  0  2  0

    Transparent UIToolbar and UINavigationBar

    Transparent UIToolbar and UINavigationBar: TransparentUIToolbarUINavigationBar.m
    [self.toolbar setBackgroundImage:[UIImage new]
                  forToolbarPosition:UIBarPositionAny
                          barMetrics:UIBarMetricsDefault];
    [self.toolbar setShadowImage:[UIImage new]
              forToolbarPosition:UIBarPositionAny];
              
    [self.navigationBar setBackgroundImage:[UIImage new]
                             forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.shadowImage = [UIImage new];
    self.navigationBar.translucent = YES;
              
    
    

    external by edwardean modified May 4, 2017  20  0  1  0

    UINavigationBar UIToolBar remove bottom line:

    UINavigationBar UIToolBar remove bottom line:: gistfile1.txt
    [self.navigationController.navigationBar setTranslucent:NO];
    [navigationBar setBackgroundImage:[UIImage imageNamed:@“NavigaionBarBackground”] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [navigationBar setShadowImage:[UIImage new]];
    
    ToolBar.clipToBounds = YES;
    
    
    • Public Snippets
    • Channels Snippets