Introduction
While working at JoyTunes on the latest versions of our top-notch piano app, we've done a great deal of UI redesign and therefore had to spend long hours with the notorious Interface Builder, resizing images and views, which can be a lot of frustrating work.
While working at JoyTunes on the latest versions of our top-notch piano app, we've done a great deal of UI redesign and therefore had to spend long hours with the notorious Interface Builder, resizing images and views, which can be a lot of frustrating work.
During this work, we actually discovered a great deal of neat IB tricks, and I decided I must share them with the world.
So I conducted this little post of my 8 greatest tips for working effectively with IB.
A little disclaimer:
In JoyTunes, we work with .xib files (not storyboards), and without Auto Layout. This is mostly for historical reasons. As a result, some of the tips I'm mentioning might react a little differently for you if you're using storyboards or Auto Layout, but most should apply just the same.
1. Size to Fit Content
I'm so ashamed I only took the effort to look this up only recently. A HUGE time saver.
Select any view and then go to Editor->Size to Fit Content or simply press ⌘=
Will resize the selected view to fit its content in the following manner:
- An ImageView/Button will be resized to the image's original size (most common usage):
- A Label/Button will be resized to fit the text it's currently containing:
- A parent container view to fit the frames of its subviews.
2. Holding option key to view distance from another view's edges
Holding option key after selecting a view, and then hovering over some other view, will show you cool distance indicators from that view's edges:
3. Editor -> Embed In View, Unembed:
Do you know that annoying feeling when you have some subviews all located and then you decide they need to have a different parent view, or even a different .xib, and then they are all automatically get located in the center of the new view?
Well - here's the solution:
4. Adding padding to freeform sized view without affecting subview's positions
When trying to add padding to a view, the x's and y's of the subview is retained, which isn't always what you want.
The best way I found to get past this, is to drag the edges while holding ⌘:
When trying to add padding to a view, the x's and y's of the subview is retained, which isn't always what you want.
The best way I found to get past this, is to drag the edges while holding ⌘:
5. Move a view that isn't in the front:
One thing that bugs me when working with IB, is the inability to move views that aren't in front easily.
One way to do so will be to temporary bring it to front and then bring it back, but this is annoying.
Another way will be to use the size inspector on the right panel, which is fine but could take some guessing and adjustments until you get it right.
A way I found of moving a view with the arrow keys without bringing it to front is this:
1. Choose the view on the document outline.
2. Click on the frame of the root view in order to gain focus.
3. Move with arrow keys.
EDIT:
Some other (better) way of gaining focus, taken from the comments to this post:
One thing that bugs me when working with IB, is the inability to move views that aren't in front easily.
One way to do so will be to temporary bring it to front and then bring it back, but this is annoying.
Another way will be to use the size inspector on the right panel, which is fine but could take some guessing and adjustments until you get it right.
A way I found of moving a view with the arrow keys without bringing it to front is this:
1. Choose the view on the document outline.
2. Click on the frame of the root view in order to gain focus.
3. Move with arrow keys.
EDIT:
Some other (better) way of gaining focus, taken from the comments to this post:
- If you double-click a view in the outline, it will switch focus to the layout pane with that view selected.
- Shift+Right(Ctrl) Click over the view in IB and you'll see a menu of all the views that exist where you've clicked.
6. IBOutletCollection ordering
Often, the order of IBOutletColletions is important to us, and we want to iterate on them in code in that order.
One way of doing it is sorting them in code by their x/y/tag, and then iterate.
This is unnecessary. The order of connection is determined by the order in which we dragged the connection, and we can see the current order if by ⌃+Clicking the File's Owner:
7. Use custom properties
I think a relatively underused feature of IB is the ability to set custom properties on views, using the "User Defined Runtime Attributes" of the Identity inspector:
As you can probably guess, we defined a JTLabel class that you can set stroke color and width to, and this is our way of immediately setting this without having to write any code.
Another common hack that can be applied this way is setting "layer.cornerRadius" of any view, to make it have rounded corners.
A relevant tool that uses this mechanism is Canvas, which will let you define animations for views without writing code.
Important warning regarding this that saved my life on one occasion:
One way of doing it is sorting them in code by their x/y/tag, and then iterate.
This is unnecessary. The order of connection is determined by the order in which we dragged the connection, and we can see the current order if by ⌃+Clicking the File's Owner:
7. Use custom properties
I think a relatively underused feature of IB is the ability to set custom properties on views, using the "User Defined Runtime Attributes" of the Identity inspector:
As you can probably guess, we defined a JTLabel class that you can set stroke color and width to, and this is our way of immediately setting this without having to write any code.
Another common hack that can be applied this way is setting "layer.cornerRadius" of any view, to make it have rounded corners.
A relevant tool that uses this mechanism is Canvas, which will let you define animations for views without writing code.
Important warning regarding this that saved my life on one occasion:
In your implementation class you cannot use initWithCoder: otherwise your key-value path setting will not be picked up. You will have to do all your implementation within awakeFromNib.
(Credit to http://www.wannabegeek.com/?p=395)
8. MoarFonts - custom fonts WYSIWYG
Custom fonts have always been a big issue when working with Interface Builder.
There's no built-in support for those, and the best solutions I have seen were either using custom properties solutions like Canvas, or using font replacing techniques like IBCustomFonts. These are valid solutions, but they have a great downside - they don't give you a full WYSIWYG experience, which is exactly why you are using Interface Builder in the first place.
It can be very annoying to place a label with a placeholder font and then having to run the app in order to discover that the width you gave it doesn't fit well with your replacing custom font.
Lately I stumbled upon this solution called MoarFonts. It costs 10$, and there's no demo or trial - but trust me, it's totally worth it!
It's a pretty simple setup: you'll have to build your app with MoarFonts as a script build phase, restart Xcode, and voila! You can see custom fonts in InterfaceBuilder:
That's it!
I hope at least some of the tips were something you didn't know.
If you have any other tips you think I should add to the list, or if you have a better way to achieve some of the stuff I was trying to solve, please send me a tweet (@theyonibomber).
Also, you should listen to my podcast about mobile development & beer (in Hebrew).
Very cool post, other than one tip, i don't know anything until now. Thank you very much!
ReplyDeleteneat tricks, thanks!
ReplyDeleteGood tips. Another tip useful for #5: If you double-click a view in the outline, it will switch focus to the layout pane with that view selected.
ReplyDeleteThanks! Edited the tip.
DeleteFantastic tips!
ReplyDeleteThere is a better way to achieve #5 though - Shift+Right(Ctrl) Click over the view in IB and you'll see a menu of all the views that exist where you've clicked. Select the one you want from the list, and you can then use the arrow keys to move it.
Thanks! It does seem like a better way. Edited the tip.
DeleteThank you! I don't know IBOutletColletions before reading this post.
ReplyDeleteThank you for the great tips...!!!
ReplyDeleteThank's - love #1 :-)
ReplyDeleteI wish I stumbled on to your #3 point "Embed in View > Unembed" a while back. It was a pain to get all those elements back in their position across 5 different views. Most of these are fantastic tips and shown with a nicer gif than a simple screenshot. Kudos!
ReplyDeleteThank you for the great post, it's very useful!!
ReplyDeleteHave noticed an anoying thing. When draging out a new image from bottom right collection of assets, the size of the UIImageView gets doubled. I have to manually resize every image I drag in.
ReplyDeleteSuch a refreshing take on this topic. Your insights are practical and easy to implement.Visit this profile Canuckle canuckle wordle for more informative content.I’ve always enjoyed word games, but Canuckle’s focus on Canadian words makes it stand out. It’s refreshing and entertaining!
Deletemy mind is good now
ReplyDeleteGood tips. We need more posts like this to know about the "tricks" there is from Xcode IB.
ReplyDeleteVIRUS REMOVAL
ReplyDeleteIs Your Computer Sluggish or Plagued With a Virus? – If So you Need Online Tech Repairs
As a leader in online computer repair, Online Tech Repairs Inc has the experience to deliver professional system optimization and virus removal.Headquartered in Great Neck, New York our certified technicians have been providing online computer repair and virus removal for customers around the world since 2004.
Our three step system is easy to use; and provides you a safe, unobtrusive, and cost effective alternative to your computer service needs. By using state-of-the-art technology our computer experts can diagnose, and repair your computer system through the internet, no matter where you are.
Our technician will guide you through the installation of Online Tech Repair Inc secure software. This software allows your dedicated computer expert to see and operate your computer just as if he was in the room with you. That means you don't have to unplug everything and bring it to our shop, or have a stranger tramping through your home.
From our remote location the Online Tech Repairs.com expert can handle any computer issue you want addressed, like:
• - System Optimization
• - How it works Software Installations or Upgrades
• - How it works Virus Removal
• - How it works Home Network Set-ups
Just to name a few.
If you are unsure of what the problem may be, that is okay. We can run a complete diagnostic on your system and fix the problems we encounter. When we are done our software is removed; leaving you with a safe, secure and properly functioning system. The whole process usually takes less than an hour. You probably couldn't even get your computer to your local repair shop that fast!
Call us now for a FREE COMPUTER DIAGONISTIC using DISCOUNT CODE (otr214427@gmail.com) on +1-914-613-3786 or chat with us on www.onlinetechrepairs.com.
These are some helpful home improvement & computer tips. Thanks for the share!
ReplyDeletei really like this News, looks great
ReplyDelete=Daily Newspapers
Online newspapers | Clippingpathaster
Free Movie | Watch
HD MOVIE | Animals News Online Dating
Laptop & Desktop repair services are now available @1-855-837-9965. No-Fix No-Fee, Cost effective Repairs and upgrades on all brands of PC's and Laptops.
ReplyDeleteThis post is very informative for everybody. I would like to appreciate your work for good accuracy and got informative knowledge from here. Nice effort, very informative, this will help me to complete my task. Thanks for sharing
ReplyDeleteOracle Fusion HCM Technical Training
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis blog explains the details of most popular technological details. This helps to learn about what are all the different method is there. And the working methods all of that are explained here. Informative blog.For more info visit our website.
ReplyDeleteFusion Cloud SCM Course Structure
Thank you for providing useful information and this is the best article blog for the students.learn Oracle Fusion Technical Online Training.
ReplyDeleteOracle Fusion Technical Online Training
Thank you for sharing such a valuable article with good information containing in this blog.learn Oracle Fusion SCM Online Training.
ReplyDeleteOracle Fusion SCM Online Training
Such a nice blog, I really like what you write in this blog, I also have some relevant Information about if you want more information.
ReplyDeleteOracle Fusion HCM Online Training
Thank you for sharing such a nice and interesting blog.
ReplyDeleteOracle Fusion SCM Online Training
https://g.co/kgs/GGvnG8
ReplyDeletehttps://bateraitanam.blogspot.com
https://bimbellampung.blogspot.com
lampungservice.com
Thank you For Sharing Useful information HR Edge Practical Training Program in Hyderabad
ReplyDeleteThanks for sharing the informative post.
ReplyDeleteRepair Shop POS
Thank you for sharing such a nice and interesting blog with us. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information.
ReplyDeleteDigital Marketing Training In Hyderabad
sem training in hyderabad
seo training in hyderabad
SMM Training In Hyderabad
Nice Blog with Good Information
ReplyDeleteSoft Online gives best training for Oracle Fusion and EBS Courses
Oracle Fusion SCM Training
Oracle Fusion HCM Training
Oracle Fusion Financials Training
For more info Visit us: www.softonlinetraining.com
Really thanks for sharing this useful blog !! This post is very informative about tips for working with interface builders . keep sharing !!
ReplyDeleteThank you for the helpful post, it's very informative!!
ReplyDeleteCloud accounting software
Contractor accounting
how to file company accounts
Living in the tech era, every computer repair business needs to systemize its business operations to provide a better solution to the clients by using Computer Repair Shop Software , It enables management to deal with routine business operations swiftly and keep working on increasing business productivity.
ReplyDeleteAivivu - đại lý chuyên vé máy bay trong nước và quốc tế
ReplyDeletevé máy bay từ hàn quốc về việt nam bao nhiêu tiền
mua vé máy bay đà nẵng sài gòn
đặt vé máy bay từ huế đi hà nội
vé máy bay đi Huế pacific airline
vé máy bay từ tphcm đi quy nhơn
This comment has been removed by the author.
ReplyDeletewordpress design agency in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!
ReplyDeleteYour words of encouragement mean the world. Core Ball is a great example of a browser-based game done right. Play it here!
ReplyDelete