Thursday 30 March 2017

Remove empty space before cells in UITableView



how to remove empty space before cell


a) Programmatically

Add this to i.e. viewDidLoad

self.automaticallyAdjustsScrollViewInsets = false
b) Interface Builder



  • Select the view controller
  • Open Attributes inspector
There's a property called "Adjust scroll view insets" in IB's attribute inspector (when a view controller is selected) which is on by default. just deselect the check box


Monday 27 March 2017

Re call function for every 5sec in iOS swift 3




override func viewDidLoad() {
        super.viewDidLoad()
var timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.getdata) , userInfo: nil, repeats: true);
}


    func getdata()
    {

//this function calls for every 5 seconds 

}

Sunday 26 March 2017

get an iPhone's device name and get Ip address in swift 3


--> Use this line for getting device name

UIDevice.current.name

-----------------------------------------------------------------------------------------------------------

-->getting ipaddress

function

func getIFAddresses() -> [String] {
        var addresses = [String]()
        
        // Get list of all interfaces on the local machine:
        var ifaddr : UnsafeMutablePointer<ifaddrs>?
        guard getifaddrs(&ifaddr) == 0 else { return [] }
        guard let firstAddr = ifaddr else { return [] }
        
        // For each interface ...
        for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
            let flags = Int32(ptr.pointee.ifa_flags)
            var addr = ptr.pointee.ifa_addr.pointee
            
            // Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
            if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
                if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) {
                    
                    // Convert interface address to a human readable string:
                    var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                    if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count),
                                    nil, socklen_t(0), NI_NUMERICHOST) == 0) {
                        let address = String(cString: hostname)
                        addresses.append(address)
                    }
                }
            }
        }
        
        freeifaddrs(ifaddr)
        return addresses

    }

Usage

 override func viewDidLoad() {
        super.viewDidLoad()
        let addr = getIFAddresses()
        print(addr[1])
        ipaddress=addr[1]
        
    }

note: add lines in -Bridging-Header.h file

#include <arpa/inet.h>

#include <sys/socket.h>


#include <ifaddrs.h>


Monday 20 March 2017

Apply font awesome styles in iOS swift 3


step 1 : download font awesome ttf file 
https://github.com/FortAwesome/Font-Awesome/blob/master/fonts/fontawesome-webfont.ttf

Step 2 : copy it into project 



Step 3 : set font awesome ttf file into "info" file



Step 4: set font awsome ttf file into Build Phases --> Copy Bundle Resources




step 5 : apply font styles to button



step 6 : 

  • use different type of icon codes


  • Icon names 
http://fontawesome.io/icons/













Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...