There is so much information and learning material available now that it is sometimes hard to know where to start or what is the best place to go especially if you are just starting out or moving onto the next level. Well for me the place I always go to first and keep returning to […]
UIView UITapGestureRecognizer
Adding a UITapGestureRecognizer to a UIView is very straighforward. All you do is setup the gesture and then assign it to the view. Could not be much easier could it.
1 2 |
let tapRecogniser = UITapGestureRecognizer(target: self, action: #selector(ViewController.viewPressed(_:))) myView.addGestureRecognizer(tapRecogniser) |
There are a couple of points just to hightlight. Firstly if you are using a UIImageView then you will need to add in the […]
UIPopoverController height
A recent project I worked on required a number of UIPopoverController screens. The api allows the implementation of these very easily in just a couple of lines as below:
1 2 3 4 5 |
let popoverViewController = UIPopoverController(contentViewController: viewController) popoverViewController.presentPopoverFromRect(CGRect(x: 195, y: 0, width: 60.0, height: 20), inView: sender, permittedArrowDirections: .Up, animated: true) |
Here i create a UIPopoverController when a button is pressed, using the sender button to presentPopoverFromRect. But what if you want to amend the size […]
UIBarButton Back Button
If you are using UINavigationController and segues, you may want to change the back button and in particular the title of the back bar button. We set this is in the function prepareForSegue:sender: Here we reference the UINavigationItem and assign it a newly created UIBarButtonItem.
1 2 3 |
let backButton = UIBarButtonItem() backButton.title = "Back" navigationItem.backBarButtonItem = backButton |
Empty Table View Cells
Let’s imagine you have setup your UITableView and populated its cells. Things are looking good but there are empty cells after your content has finished? Well, there is an easy way to hide those empty cells. Simply enter the following into ViewDidLoad() if you are using a UITableViewController or if your creating a UITableView then […]
Select a photo with UIImagePickerController
To select a photo from your library we can use the built in UIImagePickerController. This is simple to use and allows you to select and use an image already saved to your device. To start with we create a new UIImagePickerController class with: let imagePickerController = UIImagePickerController() We then assign its delegate and set its sourceType which below […]
NSDate addition using NSCalendar
If you have an NSDate and want to add a time unit onto that date, then an option is to use the NSCalendar. This will allow you to add to the date via the dateByAddingUnit, which allows you to add an NSCalendarUnit. These units could be for example: hours, days, months, years, minutes. Once you […]
App Submission – Invalid Bundle Error
I recently started seeing the following error when submitting an previously fine app within Itunes Connect: ERROR ITMS-90475: “Invalid Bundle. iPad Multitasking support requires launch story board in bundle ‘com.companyname.appname.’” After some digging into this, it turned out rather obviously to do with the new multi-tasking within Xcode 7 and IOS 9 and so you need to […]
UITableView willDisplayHeaderView
To amend the header section display in terms of colours for example on a uitableview you can utilise the UITableView Delegate protocol of tableView:willDisplayHeaderView:forSection: You can alter the background colour using the view tintColor and then by accessing the view you can amend the header text label.
1 2 3 4 5 6 7 8 |
override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { view.tintColor = UIColor.redColor() let headerView: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView headerView.textLabel.textColor = UIColor.whiteColor() } |
You can apply different styles for different section headers using the […]
UICollectionView Spacing
There are a few aspects to handling spacing and size of UICollectionViews and their cells. Lets start with the spacing around the actual uicollectionview. To do this we effectively add padding or edge insets. You can add edges to all sides of the collection view.
1 |
myCollectionView.contentInset = UIEdgeInsets(top: 7.0, left: 1.0, bottom: 144.0, right: 1.0) |
Now what about the cells within the UICollectionView. We can set […]